@@ -127,6 +127,7 @@ check_command grep ;
127127check_command python3 ;
128128test -x " $( command -v codespell) " || exit 0 ; # skip quietly if user has not installed GPL2 stuff.
129129check_command git ;
130+ check_command sed ;
130131check_command shlock ;
131132
132133
@@ -135,9 +136,15 @@ SCRIPT_FILE="tests/check_spelling"
135136# Set codespell options
136137CODESPELL_OPTIONS=" --quiet-level=4 --builtin clear,rare,code -L assertIn"
137138
139+ # Define specific typos to check for (regression tests)
140+ declare -a SPECIFIC_TYPOS=(
141+ " RECCOMENDED:RECOMMENDED"
142+ )
143+
138144function cleanup() {
139145 rm -f " ${LOCK_FILE} " 2> /dev/null || : ; wait ;
140146 # unset when done
147+ unset SPECIFIC_TYPOS 2> /dev/null || : ;
141148 unset LOCK_FILE 2> /dev/null || : ;
142149 hash -d shlock 2> /dev/null || : ;
143150}
@@ -195,11 +202,34 @@ if [[ "$1" == "--fix" ]]; then
195202fi
196203
197204# THIS IS THE ACTUAL TEST
198- # Iterate over files and run codespell
205+ # Iterate over files
199206# shellcheck disable=SC2086
200207for FILE in $FILES_TO_CHECK ; do
208+ # Part 1: Run codespell
201209 printf " ::group::%s\n" " Checking ${FILE} " ;
210+ printf " ::debug::%s\n" " Running codespell tests for typos." ;
202211 { codespell $CODESPELL_OPTIONS " ${FILE} " || EXIT_CODE=$? ; } 2> /dev/null ; wait ;
212+ # Part 2: Run specific regression tests for known typos
213+ printf " ::debug::%s\n" " Running regression tests for specific typos." ;
214+ for TYPO_PAIR in " ${SPECIFIC_TYPOS[@]} " ; do
215+ # Split the pair into typo and correction
216+ TYPO=" ${TYPO_PAIR%%:* } "
217+ CORRECTION=" ${TYPO_PAIR##*: } "
218+
219+ # Check for the specific typo
220+ if grep -q " $TYPO " " $FILE " 2> /dev/null; then
221+ printf " ::error file=%s,title=Regression Test Failed::%s\n" " ${FILE} " " Found typo '$TYPO ' (should be '$CORRECTION ')" >&2
222+ EXIT_CODE=2
223+
224+ # Auto-correct if --fix is provided
225+ if [[ " $1 " == " --fix" ]]; then
226+ { sed -i " s/$TYPO /$CORRECTION /g" " ${FILE} " 2> /dev/null && \
227+ printf " ::notice file=%s,title=Auto-corrected::%s\n" " $FILE " " Fixed typo '$TYPO ' to '$CORRECTION '" ; } || :
228+ fi
229+ fi
230+ unset TYPO 2> /dev/null || : ;
231+ unset CORRECTION 2> /dev/null || : ;
232+ done
203233 printf " ::endgroup::\n" ;
204234done
205235
0 commit comments