Update tools/tidy.sh

This commit is contained in:
Taiki Endo
2023-05-31 02:55:36 +09:00
parent 1d74f337f2
commit eacdd1887a

View File

@@ -204,6 +204,7 @@ fi
# Spell check (if config exists)
if [[ -f .cspell.json ]]; then
info "spell checking"
project_dictionary=.github/.cspell/project-dictionary.txt
if type -P npm &>/dev/null; then
has_rust=''
if [[ -n "$(git ls-files '*Cargo.toml')" ]]; then
@@ -227,7 +228,7 @@ if [[ -f .cspell.json ]]; then
if [[ -n "${has_rust}" ]]; then
dependencies_words=$(npx <<<"${dependencies}" cspell stdin --no-progress --no-summary --words-only --unique || true)
fi
all_words=$(npx cspell --no-progress --no-summary --words-only --unique $(git ls-files | (grep -v '\.github/\.cspell/project-dictionary\.txt' || true)) || true)
all_words=$(npx cspell --no-progress --no-summary --words-only --unique $(git ls-files | (grep -v "${project_dictionary//\./\\.}" || true)) || true)
# TODO: handle SIGINT
echo "${config_old}" >.cspell.json
cat >.github/.cspell/rust-dependencies.txt <<EOF
@@ -244,17 +245,17 @@ EOF
echo "+ npx cspell --no-progress --no-summary \$(git ls-files)"
if ! npx cspell --no-progress --no-summary $(git ls-files); then
error "spellcheck failed: please fix uses of above words or add to .github/.cspell/project-dictionary.txt if correct"
error "spellcheck failed: please fix uses of above words or add to ${project_dictionary} if correct"
fi
# Make sure the project-specific dictionary does not contain duplicated words.
for dictionary in .github/.cspell/*.txt; do
if [[ "${dictionary}" == .github/.cspell/project-dictionary.txt ]]; then
if [[ "${dictionary}" == "${project_dictionary}" ]]; then
continue
fi
dup=$(sed '/^$/d' .github/.cspell/project-dictionary.txt "${dictionary}" | LC_ALL=C sort -f | uniq -d -i | (grep -v '//.*' || true))
dup=$(sed '/^$/d' "${project_dictionary}" "${dictionary}" | LC_ALL=C sort -f | uniq -d -i | (grep -v '//.*' || true))
if [[ -n "${dup}" ]]; then
error "duplicated words in dictionaries; please remove the following words from .github/.cspell/project-dictionary.txt"
error "duplicated words in dictionaries; please remove the following words from ${project_dictionary}"
echo "======================================="
echo "${dup}"
echo "======================================="
@@ -263,13 +264,13 @@ EOF
# Make sure the project-specific dictionary does not contain unused words.
unused=''
for word in $(grep -v '//.*' .github/.cspell/project-dictionary.txt || true); do
for word in $(grep -v '//.*' "${project_dictionary}" || true); do
if ! grep <<<"${all_words}" -Eq -i "^${word}$"; then
unused+="${word}"$'\n'
fi
done
if [[ -n "${unused}" ]]; then
error "unused words in dictionaries; please remove the following words from .github/.cspell/project-dictionary.txt"
error "unused words in dictionaries; please remove the following words from ${project_dictionary}"
echo "======================================="
echo -n "${unused}"
echo "======================================="