aboutsummaryrefslogtreecommitdiff
path: root/spelling/check-spelling.sh
blob: 653a5f95a1ddab3905551be26a9e07617f06f72f (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
set -Eeuo pipefail

HTML_DIR="${1:-}"
[[ -z "${HTML_DIR}" ]] && {
  echo 'Undefined input HTML_DIR.' >&2
  exit 2
}

# Required by =sort= and =hunspell=
export LANG=C.UTF-8

for DICT in spelling/*.txt; do
  diff <(sort "$DICT") "$DICT" || {
    echo "The $DICT dictionary is unsorted. To fix it, run:" >&2
    echo "  LANG=C.UTF-8 sort $DICT | sponge $DICT" >&2
    exit 1
  }
done

finish() {
  rm -f spelling.txt
  rm -f dicts.txt
}
trap finish EXIT

cat spelling/*.txt > dicts.txt

find "${HTML_DIR}" -type f -name '*.html' | grep -v pastebin | hunspell -l -p dicts.txt -d fr_FR -d en_US -i utf-8 >> spelling.txt

if [[ -s spelling.txt ]]; then
  printf "\nvvv Mispelled words detected by hunspell.\n\n" >&2
  sort < spelling.txt | uniq >&2
  printf "\n^^^\n" >&2
  exit 1
else
  echo "No words mispelled" >&2
fi