|
| 1 | +#!/usr/bin/env bash |
| 2 | +# This program is free software; you can redistribute it and/or modify |
| 3 | +# it under the terms of the GNU General Public License as published by |
| 4 | +# the Free Software Foundation; either version 2 of the License, or |
| 5 | +# (at your option) any later version. |
| 6 | +# |
| 7 | +# This program is distributed in the hope that it will be useful, |
| 8 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +# GNU Library General Public License for more details. |
| 11 | +# |
| 12 | +# You should have received a copy of the GNU General Public License |
| 13 | +# along with this program; if not, write to the Free Software |
| 14 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 15 | +# |
| 16 | +# spellintian.sh |
| 17 | +# Copyright (C) 2023 Perry Naseck, Peter Newman |
| 18 | + |
| 19 | +# This script is based on Travis CI tests by Peter Newman |
| 20 | +current_test="" |
| 21 | +if [ "$1" = "spellintian" ]; then |
| 22 | + current_test="spellintian" |
| 23 | +elif [ "$1" = "codespell" ]; then |
| 24 | + current_test="codespell" |
| 25 | +else |
| 26 | + echo "Unknown test \"$1\" specified in first argument. Options are spellintian and codespell." |
| 27 | + exit 1; |
| 28 | +fi; |
| 29 | + |
| 30 | +if ! [ -x "$(command -v zrun)" ]; then |
| 31 | + echo "error: Cannot find zrun. Do you need the moreutils package?" |
| 32 | + exit 1; |
| 33 | +fi; |
| 34 | +if [ $current_test = "spellintian" ] && ! [ -x "$(command -v spellintian)" ]; then |
| 35 | + echo "error: Cannot find spellintian. Do you need the lintian package?" |
| 36 | + exit 1; |
| 37 | +fi; |
| 38 | +if [ $current_test = "codespell" ] && ! [ -x "$(command -v codespell)" ]; then |
| 39 | + echo "error: Cannot find codespell. Install via pip." |
| 40 | + exit 1; |
| 41 | +fi; |
| 42 | + |
| 43 | +SPELLINGBLACKLIST=$(cat <<-BLACKLIST |
| 44 | + -wholename "./.codespellignorelines" -or \ |
| 45 | + -wholename "./.codespellignorewords" -or \ |
| 46 | + -wholename "./.git/*" -or \ |
| 47 | + -wholename "./Makefile" -or \ |
| 48 | + -wholename "./Makefile.in" -or \ |
| 49 | + -wholename "./aclocal.m4" -or \ |
| 50 | + -wholename "./autom4te.cache/*" -or \ |
| 51 | + -wholename "./common/protocol/Ola.pb.*" -or \ |
| 52 | + -wholename "./common/rpc/TestService.pb.*" -or \ |
| 53 | + -wholename "./config.log" -or \ |
| 54 | + -wholename "./config.status" -or \ |
| 55 | + -wholename "./config/config.guess" -or \ |
| 56 | + -wholename "./config/config.sub" -or \ |
| 57 | + -wholename "./config/depcomp" -or \ |
| 58 | + -wholename "./config/install-sh" -or \ |
| 59 | + -wholename "./config/libtool.m4" -or \ |
| 60 | + -wholename "./config/ltmain.sh" -or \ |
| 61 | + -wholename "./config/ltoptions.m4" -or \ |
| 62 | + -wholename "./config/ltsugar.m4" -or \ |
| 63 | + -wholename "./config/missing" -or \ |
| 64 | + -wholename "./configure" -or \ |
| 65 | + -wholename "./java/Makefile" -or \ |
| 66 | + -wholename "./java/Makefile.in" -or \ |
| 67 | + -wholename "./libtool" -or \ |
| 68 | + -wholename "./olad/www/mobile.js" -or \ |
| 69 | + -wholename "./olad/www/new/js/app.min.js" -or \ |
| 70 | + -wholename "./olad/www/new/js/app.min.js.map" -or \ |
| 71 | + -wholename "./olad/www/new/libs/angular/js/angular.min.js" -or \ |
| 72 | + -wholename "./olad/www/new/libs/marked/js/marked.min.js" -or \ |
| 73 | + -wholename "./olad/www/ola.js" -or \ |
| 74 | + -wholename "./plugins/artnet/messages/ArtNetConfigMessages.pb.*" -or \ |
| 75 | + -wholename "./tools/ola_trigger/config.tab.*" -or \ |
| 76 | + -wholename "./tools/ola_trigger/lex.yy.cpp" |
| 77 | +BLACKLIST |
| 78 | +) |
| 79 | + |
| 80 | +spellingfiles=$(eval "find ./ -type f -and ! \( \ |
| 81 | + $SPELLINGBLACKLIST \ |
| 82 | + \) | xargs") |
| 83 | + |
| 84 | +if [ $current_test = "spellintian" ]; then |
| 85 | + # count the number of spellintian errors, including duplicate words |
| 86 | + # spellintian does not change the exit code, so the output must be checked |
| 87 | + spellintian_issues="$(zrun spellintian $spellingfiles 2>&1)" |
| 88 | + |
| 89 | + if [[ -n $spellintian_issues ]]; then |
| 90 | + printf "%s\n" "$spellintian_issues" |
| 91 | + # For now we always exit with success, as these errors are manually checked |
| 92 | + # TODO: Actively match and skip printing known false positives, exit with |
| 93 | + # errors properly. |
| 94 | + # exit 1; |
| 95 | + exit 0; |
| 96 | + fi; |
| 97 | +elif [ $current_test = "codespell" ]; then |
| 98 | + if ! zrun codespell --interactive 0 --check-filenames --check-hidden \ |
| 99 | + --quiet 2 --regex "[a-zA-Z0-9][\\-'a-zA-Z0-9]+[a-zA-Z0-9]" \ |
| 100 | + --exclude-file .codespellignorelines \ |
| 101 | + --ignore-words .codespellignorewords $spellingfiles 2>&1; then |
| 102 | + exit 1; |
| 103 | + fi; |
| 104 | +fi; |
0 commit comments