diff mbox series

[v3] devtools: spell check

Message ID 20211201144743.30560-1-hnadeau@iol.unh.edu (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series [v3] devtools: spell check | expand


Context Check Description
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Henry Nadeau Dec. 1, 2021, 2:47 p.m. UTC
A spell check script to check for errors in patches. An
 example of usage being cat PATCH_FILE | spell_check.sh.
 Errors will be printed to console, following the file
 they are located in. Word exclusions can be made by
 making additions to the dictionary, and problematic
 patterns can be added to the regex filter.

 devtools/spell_check.sh             |  115 ++
 devtools/spell_check_dictionary.txt | 2160 +++++++++++++++++++++++++++
 devtools/spell_check_regex.txt      |    2 +
 3 files changed, 2277 insertions(+)
 create mode 100755 devtools/spell_check.sh
 create mode 100644 devtools/spell_check_dictionary.txt
 create mode 100644 devtools/spell_check_regex.txt
diff mbox series


diff --git a/devtools/spell_check.sh b/devtools/spell_check.sh
new file mode 100755
index 0000000000..a8f8331fd2
--- /dev/null
+++ b/devtools/spell_check.sh
@@ -0,0 +1,115 @@ 
+dir=$(git rev-parse --show-toplevel)
+if [ -z "$dir" ]; then
+  echo "Please execute this script from within a git repo"
+  exit 1
+# function to spell check a single file
+function spellcheck() {
+	echo "$3" | sed "$2" | aspell --lang=en --encoding=utf-8 --ignore-case --ignore=3 --ignore-repl list --personal="$1""/devtools/spell_check_dictionary.txt"
+function read_input {
+  while read -r data; do
+    echo "$data"
+  done
+while test $# -gt 0; do
+	case "$1" in
+	-h | --help)
+		echo "Spell Check"
+		echo " "
+		echo "spell_check [options] [arguments]"
+		echo " "
+		echo "options:"
+		echo "-h, --help    Show shows list of flags and usages."
+		echo "-e            Excludes file (and dir) from being printed."
+		echo "-output-dir=            Output file."
+		exit 0
+		;;
+	-e)
+		shift
+		export simple_out='true'
+		;;
+	--output-dir*)
+		export output_dir=$(echo $1 | sed -e 's/^[^=]*=//g')
+		shift
+		;;
+	*)
+		break
+		;;
+	esac
+# requires patch file be piped into script
+PATCH_FILE=$(echo "$PATCH_FILE" | sed 's/``.*``//' | grep ^+ | tr -d '*')
+# Build regex pattern from files
+while IFS= read -r line; do
+  if [[ ! $line =~ "#" ]]; then
+    regex_pattern+="s/$line/ /; "
+  fi
+done < "$dir/devtools/spell_check_regex.txt"
+if [ -n "$regex_pattern" ]; then
+  regex_pattern="${regex_pattern::-1}"
+if [ 's// /;' = "$regex_pattern" ]; then
+  regex_pattern=''
+while IFS= read -r line; do
+  if [[ ($line =~ ^\+\+\+) && ($line =~ .rst$)]]; then # if line is a file and rst echo and reset flag
+    output=$output"${line//+++ b\//}"$'\n'
+    ((file_count=file_count+1))
+    non_doc=0
+    continue
+  elif [[ ($line =~ ^\+\+\+) && (! $line =~ .rst$)]]; then # if line is a file and not rst set flag
+    non_doc=1
+    continue;
+  fi
+  if [[ ($non_doc = 0 ) && (! $line =~ ^\+\+\+)]]; then # only when non_doc isn't set & line is not a file
+    line=${line/+  /}
+    line=${line/+/}
+    for word in $line;
+    do
+	error=$(spellcheck "$dir" "$regex_pattern" "$(echo "$word" |
+	sed 's/>/ /;
+	     s/</ /;
+	     s/:/ /;
+	     s/:/ /;
+	     s/\*/ /;
+	     s/\+/ /;
+	     s/`/ /;
+	     s/"/ /;')")
+	if [ -n "$error" ]; then
+	  output=$output$error$'\n'
+	  ((error_count=error_count+1))
+	fi
+    done
+  fi
+done <<< "$PATCH_FILE"
+if [ -z "$simple_out" ]; then
+      echo "$output""Errors: $error_count"
+elif [ -n "$output_dir" ]; then
+  touch "$output_dir"
+  echo "$output""Errors: $error_count"$'\n' >> "$output_dir"
+exit 0
diff --git a/devtools/spell_check_dictionary.txt b/devtools/spell_check_dictionary.txt
new file mode 100644
index 0000000000..8a10d942d3
--- /dev/null
+++ b/devtools/spell_check_dictionary.txt
@@ -0,0 +1,2160 @@ 
+personal_ws-1.1 en 1
diff --git a/devtools/spell_check_regex.txt b/devtools/spell_check_regex.txt
new file mode 100644
index 0000000000..efa8f63450
--- /dev/null
+++ b/devtools/spell_check_regex.txt
@@ -0,0 +1,2 @@ 
+# This file is used to exclude regex patterns from being passed to Aspell.
+# Each line is read as a single pattern.