mirror of
https://github.com/FreeRTOS/coreMQTT
synced 2025-05-24 00:22:02 +08:00
Use spellcheck from the CSDK repo (#43)
This commit is contained in:
parent
f3484dd17f
commit
4041d4a173
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
@ -64,7 +64,16 @@ jobs:
|
||||
spell-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Checkout Parent Repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: master
|
||||
repository: aws/aws-iot-device-sdk-embedded-C
|
||||
- run: rm -r libraries/standard/coreMQTT
|
||||
- name: Clone This Repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: libraries/standard/coreMQTT
|
||||
- name: Install spell
|
||||
run: |
|
||||
sudo apt-get install spell
|
||||
@ -72,7 +81,15 @@ jobs:
|
||||
- name: Check spelling
|
||||
run: |
|
||||
PATH=$PATH:$PWD/tools/spell
|
||||
for lexfile in `find . -name lexicon.txt`; do dir=${lexfile%/lexicon.txt}; find-unknown-comment-words --directory $dir; if [ $? -ne "0" ]; then exit 1; fi; done;
|
||||
for lexfile in `find libraries/standard/coreMQTT -name lexicon.txt`
|
||||
do dir=${lexfile%/lexicon.txt}
|
||||
echo $dir
|
||||
find-unknown-comment-words --directory $dir
|
||||
if [ $? -ne "0" ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
formatting:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -1,30 +0,0 @@
|
||||
# Pre-requisites to running the spell check scripts
|
||||
|
||||
1. In your GNU environment, install the *spell* and *getopt* programs. Use the following commands in Debian distributions, to install the packages (*getopt* is part of the `util-linux` package):
|
||||
```shell
|
||||
apt-get install spell
|
||||
apt-get install util-linux
|
||||
```
|
||||
|
||||
1. Add the folder containing the **tools/spell/ablexicon**, **tools/spell/extract-comments**, and **tools/spell/find-unknown-comment-words** scripts to your system's PATH.
|
||||
```shell
|
||||
export PATH=<REPO_ROOT>/tools/spell:$PATH
|
||||
```
|
||||
|
||||
# How to create a lexicon.txt for a new directory.
|
||||
|
||||
1. Ensure there does not exist a file called "lexicon.txt" in the directory. Run the following command to create a lexicon.txt for the directory:
|
||||
```shell
|
||||
find-unknown-comment-words -d <PATH>/<TO>/<DIRECTORY> > <PATH>/<TO>/<DIRECTORY>/lexicon.txt
|
||||
```
|
||||
|
||||
1. Check the contents of *<PATH>/<TO>/<DIRECTORY>* for any misspelled words. Fix them in your library's source code and delete them from the lexicon.txt.
|
||||
|
||||
# How to run for changes to an existing directory containing lexicon.txt file.
|
||||
|
||||
1. If there exists a lexicon.txt in a directory, run the following command:
|
||||
```shell
|
||||
find-unknown-comment-words -d <PATH>/<TO>/<DIRECTORY>
|
||||
```
|
||||
|
||||
1. Add any non-dictionary correctly spelled words to *<PATH>/<TO>/<DIRECTORY>/lexicon.txt*. Fix any misspelled words in your code comment change.
|
@ -1,96 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ablexicon - Compare an input list of words against a dictionary and
|
||||
# optional lexicon. If any words are in neither the dictionary nor the
|
||||
# lexicon, log them to stdout.
|
||||
#
|
||||
set -e
|
||||
set -f
|
||||
|
||||
function usage () {
|
||||
echo "Find occurrences of non-dictionary/lexicon words"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " ${0##*/} [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -f, --file source text (defaults to /dev/fd/0)"
|
||||
echo " -l, --lexicon lexicon file (one word per line)"
|
||||
echo " -h, --help display this help"
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Verify that required commands are present
|
||||
#
|
||||
REQUIRED=( "spell" "getopt" )
|
||||
for i in "${REQUIRED[@]}"
|
||||
do
|
||||
command -v $i"" >/dev/null
|
||||
if [ $? -ne "0" ]
|
||||
then
|
||||
echo "'"$i"' must be installed, exiting...">&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
GETOPT_OUT=`getopt -o hf:l: --long help,file:,lexicon: -n "${0##*/}" -- "$@"`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "Exiting..." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval set -- "$GETOPT_OUT"
|
||||
|
||||
INFILE=/dev/fd/0
|
||||
LEXICON=/dev/null
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h | --help ) usage $0 ;;
|
||||
-f | --file ) INFILE="$2"; shift 2 ;;
|
||||
-l | --lexicon ) LEXICON="$2"; shift 2 ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f $INFILE"" ] && [ $INFILE"" != /dev/fd/0 ]
|
||||
then
|
||||
echo "Invalid input file"
|
||||
usage
|
||||
fi
|
||||
#
|
||||
# Read the lexicon into an array
|
||||
#
|
||||
readarray -t lexicon < $LEXICON""
|
||||
lexicon_size="${#lexicon[@]}"
|
||||
|
||||
#
|
||||
# Search for all input words in the dictionary
|
||||
# and sort the output
|
||||
#
|
||||
for word in `cat $INFILE"" | spell | sort -u`
|
||||
do
|
||||
#
|
||||
# Search for each remaining word in the lexicon
|
||||
#
|
||||
found="false"
|
||||
i="0"
|
||||
while [[ "$i" -lt "$lexicon_size" ]] && [ "$found" == "false" ]
|
||||
do
|
||||
if [ "${lexicon[i]}" == "$word" ]
|
||||
then
|
||||
found="true"
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
if [ $found"" == "false" ]
|
||||
then
|
||||
#
|
||||
# The word is neither in the dictionary nor the lexicon, send
|
||||
# it to stdout.
|
||||
#
|
||||
echo $word
|
||||
fi
|
||||
done
|
@ -1,41 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Extract comments from C/C++ files
|
||||
#
|
||||
set -e
|
||||
set -f
|
||||
|
||||
function usage () {
|
||||
echo "Extract comments from C/C++ files"
|
||||
echo ""
|
||||
echo "usage: "${0##*/}" file-list"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
usage $0
|
||||
fi
|
||||
|
||||
if [ $1 = "-h" ] || [ $1 == "--help" ]
|
||||
then
|
||||
usage $0
|
||||
fi
|
||||
|
||||
while test $# -gt 0
|
||||
do
|
||||
if [ ! -f $1 ]
|
||||
then
|
||||
echo $0": '"$1"' is not a file." 2>/dev/null
|
||||
exit 1
|
||||
fi
|
||||
#
|
||||
# Extract all words from C/C++ language comments; add line
|
||||
# numbers to aid in searching.
|
||||
#
|
||||
# NOTE: This has some limitations. For example, it prints
|
||||
# non-comment text at the beginning of a comment line.
|
||||
#
|
||||
nl -ba $1 | awk '/\/\// {print $0}; /\/\*/ {comment=1}; {if(comment) print $0}; /\*\// {comment=0}'
|
||||
shift
|
||||
done
|
@ -1,152 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Locate unknown words in C/C++ comments. Uses "extract-comments"
|
||||
# and "ablexicon" scripts.
|
||||
#
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
set -o errexit
|
||||
set -f
|
||||
|
||||
BLUE="\e[1;34m"
|
||||
GREEN="\e[1;32m"
|
||||
DEFAULTFG="\e[39m"
|
||||
|
||||
function usage () {
|
||||
echo "Find unknown words in C/C++ comments"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " ${0##*/} [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -d, --directory directory to scan (defaults to .)"
|
||||
echo " -l, --lexicon lexicon file (one word per line, default 'lexicon.txt')"
|
||||
echo " -t, --terse terse output only (enabled if no lexicon available)"
|
||||
echo " -h, --help display this help"
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Verify that required commands are present
|
||||
#
|
||||
REQUIRED=( "extract-comments" "ablexicon" "getopt" )
|
||||
for i in "${REQUIRED[@]}"
|
||||
do
|
||||
command -v $i"" >/dev/null
|
||||
if [ $? -ne "0" ]
|
||||
then
|
||||
echo "Can't find '"$i"' , exiting...">&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
GETOPT_OUT=`getopt -o htd:l: --long help,terse,directory:,lexicon: -n "${0##*/}" -- "$@"`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "Exiting..." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval set -- "$GETOPT_OUT"
|
||||
|
||||
DIRNAME=/dev/fd/0
|
||||
LEXICON=
|
||||
STATUS=
|
||||
TERSE=
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h | --help ) usage $0 ;;
|
||||
-t | --terse ) TERSE=1; shift ;;
|
||||
-d | --directory ) DIRNAME="$2"; shift 2 ;;
|
||||
-l | --lexicon ) LEXICON="$2"; shift 2 ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -d $DIRNAME"" ]
|
||||
then
|
||||
echo "Invalid directory: "$DIRNAME
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ $LEXICON"" = "" ]
|
||||
then
|
||||
if [ -f $DIRNAME/lexicon.txt ]
|
||||
then
|
||||
LEXICON=$DIRNAME/lexicon.txt
|
||||
else
|
||||
LEXICON=/dev/null
|
||||
TERSE=1
|
||||
fi
|
||||
fi
|
||||
|
||||
TMPFILE=${0##*/}-$USER-$RANDOM
|
||||
unknowns=( "not-used" ) # get around empty array with nounset
|
||||
extract-comments `find $DIRNAME -name \*.[ch]` |
|
||||
tr [:upper:] [:lower:] |
|
||||
grep -o -E '[a-zA-Z]+' |
|
||||
ablexicon -l $LEXICON > $TMPFILE
|
||||
readarray -O 1 -t unknowns < $TMPFILE
|
||||
rm -f $TMPFILE
|
||||
|
||||
for word in "${unknowns[@]}"
|
||||
do
|
||||
if [ $word"" == "not-used" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ $TERSE"" != "" ]
|
||||
then
|
||||
echo $word
|
||||
continue
|
||||
fi
|
||||
|
||||
for file in `find $DIRNAME -name \*.[ch]`
|
||||
do
|
||||
# Each submodule in this repo is ignored.
|
||||
if [[ $file == *"CMock"* ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
if [[ $file == *"aws-templates-for-cbmc-proofs"* ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
# Disable errexit here, extract-comments can return non-zero
|
||||
set +e
|
||||
#
|
||||
# A little inefficient here; we will grep twice, once to detect
|
||||
# the unknown word and another to print it with color highlighting.
|
||||
# If there's a way to preserve ANSI color output with the first
|
||||
# search and reuse it within the if statement (I gave up trying
|
||||
# to find one after a few minutes), that would be nice.
|
||||
#
|
||||
extract-comments $file | grep -iw $word > /dev/null
|
||||
if [ $? == "0" ]
|
||||
then
|
||||
if [ $STATUS"" != "1" ]
|
||||
then
|
||||
echo -e $GREEN"############################################################################"$DEFAULTFG
|
||||
echo -e $GREEN"#"$DEFAULTFG
|
||||
echo -e $GREEN"# Unknown word(s) found. Please either correct the spelling or add them"$DEFAULTFG
|
||||
echo -e $GREEN"# to the lexicon file '"$LEXICON"'".$DEFAULTFG
|
||||
echo -e $GREEN"#"$DEFAULTFG
|
||||
echo -e $GREEN"############################################################################"$DEFAULTFG
|
||||
STATUS=1 # Return non-zero status if any unidentified words are found
|
||||
fi
|
||||
echo ""
|
||||
echo -e $BLUE$file$DEFAULTFG
|
||||
echo ""
|
||||
extract-comments $file | grep --color=always -iw $word | GREP_COLORS="mt=01;32" grep --color=always -E -e '^[ \t]*[0-9]+'
|
||||
fi
|
||||
# Re-enable errexit
|
||||
set -o errexit
|
||||
done
|
||||
done
|
||||
|
||||
if [ $STATUS"" = "1" ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user