spellcheck 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # shellcheck disable=SC2015
  3. set -euo pipefail
  4. aspell -v > /dev/null && [ "$#" -eq 1 ] || {
  5. echo "Usage:
  6. $(basename "$0") check
  7. or
  8. $(basename "$0") fix
  9. Note: this script needs aspell to run"
  10. exit 1
  11. }
  12. action=$1
  13. dict_dir="$(git rev-parse --show-toplevel)/$(dirname "$0")/dict"
  14. echo "${dict_dir}"
  15. dict="${dict_dir}/.aspell.en"
  16. export fail=0
  17. aspellcmd() {
  18. local mode
  19. mode="${1}"
  20. shift
  21. aspell --mode "${mode}" --camel-case --add-filter html --add-html-skip code -p "$dict" "$@"
  22. }
  23. check() {
  24. local mode file typos ntypos
  25. mode="$1"
  26. file="$2"
  27. echo "!! Spellchecking ${file}"
  28. typos="$(mktemp)"
  29. echo "!! Typos:"
  30. aspellcmd "$mode" list < "$file" |
  31. sort -u |
  32. tee "$typos"
  33. ntypos="$(wc -l "$typos")"
  34. rm "$typos"
  35. [ "$ntypos" = 0 ] || export fail=1
  36. }
  37. fix() {
  38. local mode file
  39. mode=$1
  40. file=$2
  41. aspellcmd "$mode" check "$file"
  42. }
  43. case $action in
  44. fix)
  45. for i in $(git ls-tree -r --name-only HEAD | grep -E '_schema.erl$'); do
  46. fix perl "$i"
  47. done
  48. # for i in $(git ls-tree -r --name-only HEAD | grep -E '.md$'); do
  49. # fix markdown $i
  50. # done
  51. ;;
  52. *)
  53. check markdown _build/emqx/lib/emqx_dashboard/priv/www/static/config.md
  54. esac
  55. if [ $fail -eq 1 ]; then
  56. echo
  57. echo "!! Bad spelling in the documentation. Run script in fix mode to resolve problems."
  58. exit 1
  59. fi