Skip to content
Snippets Groups Projects
Commit 97108dac authored by Jan Frenzel's avatar Jan Frenzel
Browse files

Added --all option to check-spelling.sh.

parent bce1a91d
No related branches found
No related tags found
3 merge requests!446docs: Add Jupyter Teaching Example,!423Automated merge from preview to main,!421Added --all option to check-spelling.sh.
......@@ -7,6 +7,7 @@ basedir=`dirname "$scriptpath"`
basedir=`dirname "$basedir"`
wordlistfile=$(realpath $basedir/wordlist.aspell)
branch="origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-preview}"
files_to_skip=(doc.zih.tu-dresden.de/docs/accessibility.md doc.zih.tu-dresden.de/docs/data_protection_declaration.md data_protection_declaration.md)
aspellmode=
if aspell dump modes | grep -q markdown; then
aspellmode="--mode=markdown"
......@@ -14,9 +15,10 @@ fi
function usage() {
cat <<-EOF
usage: $0 [file]
usage: $0 [file | -a]
If file is given, outputs all words of the file, that the spell checker cannot recognize.
If file is omitted, checks whether any changed file contains more unrecognizable words than before the change.
If parameter -a (or --all) is given instead of the file, checks all markdown files.
Otherwise, checks whether any changed file contains more unrecognizable words than before the change.
If you are sure a word is correct, you can put it in $wordlistfile.
EOF
}
......@@ -29,12 +31,52 @@ function getNumberOfAspellOutputLines(){
getAspellOutput | wc -l
}
function isMistakeCountIncreasedByChanges(){
any_fails=false
function isWordlistSorted(){
#Unfortunately, sort depends on locale and docker does not provide much.
#Therefore, it uses bytewise comparison. We avoid problems with the command tr.
if ! sed 1d "$wordlistfile" | tr [:upper:] [:lower:] | sort -C; then
return 1
fi
return 0
}
function shouldSkipFile(){
printf '%s\n' "${files_to_skip[@]}" | grep -xq $1
}
function checkAllFiles(){
any_fails=false
if isWordlistSorted; then
echo "Unsorted wordlist in $wordlistfile"
any_fails=true
fi
files=$(git ls-tree --full-tree -r --name-only HEAD $basedir/ | grep .md)
while read file; do
if [ "${file: -3}" == ".md" ]; then
if shouldSkipFile ${file}; then
echo "Skip $file"
else
echo "Check $file"
echo "-- File $file"
if { cat "$file" | getAspellOutput | tee /dev/fd/3 | grep -xq '.*'; } 3>&1; then
any_fails=true
fi
fi
fi
done <<< "$files"
if [ "$any_fails" == true ]; then
return 1
fi
return 0
}
function isMistakeCountIncreasedByChanges(){
any_fails=false
if isWordlistSorted; then
echo "Unsorted wordlist in $wordlistfile"
any_fails=true
fi
......@@ -48,9 +90,7 @@ function isMistakeCountIncreasedByChanges(){
while read oldfile; do
read newfile
if [ "${newfile: -3}" == ".md" ]; then
if [[ $newfile == *"accessibility.md"* ||
$newfile == *"data_protection_declaration.md"* ||
$newfile == *"legal_notice.md"* ]]; then
if shouldSkipFile ${newfile:2}; then
echo "Skip $newfile"
else
echo "Check $newfile"
......@@ -90,6 +130,9 @@ if [ $# -eq 1 ]; then
usage
exit
;;
-a | --all)
checkAllFiles
;;
*)
cat "$1" | getAspellOutput
;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment