diff --git a/doc.zih.tu-dresden.de/util/check-code-style.sh b/doc.zih.tu-dresden.de/util/check-code-style.sh index b569bf2ece7fad4c1c7dc91945c6b7c1af21d313..306ca5c16f3cfc0a6b37d33f38df69337874cd1b 100755 --- a/doc.zih.tu-dresden.de/util/check-code-style.sh +++ b/doc.zih.tu-dresden.de/util/check-code-style.sh @@ -46,20 +46,20 @@ function pattern_matches() { test_res_count=0 if [[ "${ext}" == "sh" ]]; then # If shell script is provided - if grep -qP "${pattern}" "$myfile"; then + if grep -qP "${pattern}" "${myfile}"; then echo -e "[WARNING] ${warning}" echo "[WARNING] This coding style was not used for following lines in file $(realpath "${myfile}"):" - grep -nP "${pattern}" "$myfile" + grep -nP "${pattern}" "${myfile}" echo "" return 0 fi elif [[ "${ext}" == "md" ]]; then # If markdown file is provided # Check if the code snippet exists in the markdown file - if sed -n '/^```bash$/,/^```$/p' "$myfile" | grep -qv '```'; then + if sed -n '/^```bash$/,/^```$/p' "${myfile}" | grep -qv '```'; then # Extracting code snippet within ```bash ... ``` local test_string - test_string=$(sed -n '/^```bash$/,/^```$/p' "$myfile" | grep -v '```') + test_string=$(sed -n '/^```bash$/,/^```$/p' "${myfile}" | grep -v '```') # Check the exit code of pattern match if echo "${test_string}" | grep -qP "${pattern}"; then @@ -95,7 +95,7 @@ if [[ $# -eq 1 ]]; then ;; -a | --all) echo "Checking in all files." - files=$(find "$basedir" -name '*.md' -o -name '*.sh') + files=$(find "${basedir}" -name '*.md' -o -name '*.sh') ;; *) files="$1" @@ -103,7 +103,7 @@ if [[ $# -eq 1 ]]; then esac elif [[ $# -eq 0 ]]; then echo "Search in git-changed files." - files=$(git diff --name-only "$(git merge-base HEAD "$branch")" | grep -e '.md$' -e '.sh$' || true) + files=$(git diff --name-only "$(git merge-base HEAD "${branch}")" | grep -e '.md$' -e '.sh$' || true) else usage fi @@ -112,7 +112,7 @@ any_fails=false for file in ${files}; do # Skip the check of this current ($0) script. - if echo "${file}" | grep -qP "check-code-style.sh$"; then + if [[ "${file}" =~ check-code-style.sh$ ]]; then continue fi @@ -133,11 +133,15 @@ for file in ${files}; do # Line length less than 100 char length file_ext="${file##*.}" if [[ "${file_ext}" == "sh" ]]; then - #echo "Checking for max line length..." - pattern='^.{100}.*$' - warning="Recommended maximum line length is 100 characters." - if pattern_matches "${file}" "${pattern}" "${warning}"; then - any_fails=true + if [[ "${file}" =~ grep-forbidden-patterns.sh$ ]]; then + : # skip + else + #echo "Checking for max line length..." + pattern='^.{100}.*$' + warning="Recommended maximum line length is 100 characters." + if pattern_matches "${file}" "${pattern}" "${warning}"; then + any_fails=true + fi fi fi diff --git a/doc.zih.tu-dresden.de/util/check-spelling.sh b/doc.zih.tu-dresden.de/util/check-spelling.sh index 5c8e1336388050bc69c0c9767a29c0df1aaab19f..c2a4260156bd701f715f10db6a07c5d001e611b7 100755 --- a/doc.zih.tu-dresden.de/util/check-spelling.sh +++ b/doc.zih.tu-dresden.de/util/check-spelling.sh @@ -7,7 +7,12 @@ 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 doc.zih.tu-dresden.de/docs/legal_notice.md doc.zih.tu-dresden.de/docs/access/key_fingerprints.md) +files_to_skip=( +doc.zih.tu-dresden.de/docs/accessibility.md +doc.zih.tu-dresden.de/docs/data_protection_declaration.md +doc.zih.tu-dresden.de/docs/legal_notice.md +doc.zih.tu-dresden.de/docs/access/key_fingerprints.md +) aspellmode= if aspell dump modes | grep -q markdown; then aspellmode="--mode=markdown" @@ -18,7 +23,7 @@ function usage() { usage: $0 [file | -a] If file is given, outputs all words of the file, that the spell checker cannot recognize. 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. +Otherwise, checks whether any changed file has more unrecognizable words than before the change. If you are sure a word is correct, you can put it in ${wordlistfile}. EOF } @@ -98,7 +103,8 @@ function is_mistake_count_increased_by_changes(){ #Added files should not introduce new spelling mistakes previous_count=0 else - previous_count=`git show "${source_hash}:${oldfile:2}" | get_number_of_aspell_output_lines` + previous_count=`git show "${source_hash}:${oldfile:2}" \ + | get_number_of_aspell_output_lines` fi if [[ "${newfile}" == "/dev/null" ]]; then #Deleted files do not contain any spelling mistakes @@ -109,8 +115,11 @@ function is_mistake_count_increased_by_changes(){ current_count=`cat "${newfile}" | get_number_of_aspell_output_lines` fi if [[ ${current_count} -gt ${previous_count} ]]; then - echo "-- File ${newfile}" - echo "Change increases spelling mistake count (from ${previous_count} to ${current_count}), misspelled/unknown words:" + cat <<-EOF +-- File ${newfile} +Change increases spelling mistakes from ${previous_count} to ${current_count}. +Misspelled/unknown words: +EOF cat "${newfile}" | get_aspell_output any_fails=true fi