tidy: Improve performance of spellcheck

This commit is contained in:
Taiki Endo
2023-03-10 00:41:57 +09:00
parent 0ffbddd290
commit 045dd4076c

View File

@@ -170,30 +170,28 @@ if [[ -f .cspell.json ]]; then
dependencies+=$(jq <<<"${metadata}" ".packages[] | select(.id == ${id})" | jq -r '.dependencies[].name')
done
done
words=''
# shellcheck disable=SC2001
for word in $(sed <<<"${dependencies}" 's/[0-9_-]/\n/g' | LC_ALL=C sort -f -u | (grep -E '.{4,}' || true)); do
# Skip if the word is contained in other dictionaries.
if ! npx cspell trace "${word}" 2>/dev/null | (grep -v -E '/(project-dictionary|rust-dependencies)\.txt' || true) | grep -Eq "^${word} \* [0-9A-Za-z_-]+\* "; then
words+=$'\n'
words+="${word}"
fi
done
dependencies=$(sed <<<"${dependencies}" 's/[0-9_-]/\n/g' | LC_ALL=C sort -f -u)
config_old=$(<.cspell.json)
config_new=$(grep <<<"${config_old}" -v ' *//' | jq 'del(.dictionaries[] | select(index("organization-dictionary") | not))' | jq 'del(.dictionaryDefinitions[] | select(.name == "organization-dictionary" | not))')
echo "${config_new}" >.cspell.json
words=$(npx <<<"${dependencies}" cspell stdin --no-progress --no-summary --words-only --unique || true)
echo "${config_old}" >.cspell.json
fi
cat >.github/.cspell/rust-dependencies.txt <<EOF
// This file is @generated by $(basename "$0").
// It is not intended for manual editing.
EOF
if [[ -n "${words:-}" ]]; then
echo "${words}" >>.github/.cspell/rust-dependencies.txt
echo $'\n'"${words}" >>.github/.cspell/rust-dependencies.txt
fi
check_diff .github/.cspell/rust-dependencies.txt
if ! grep -Eq "^\.github/\.cspell/rust-dependencies.txt linguist-generated" .gitattributes; then
echo "warning: you may want to mark .github/.cspell/rust-dependencies.txt linguist-generated"
fi
echo "+ npx cspell --no-progress \$(git ls-files)"
npx cspell --no-progress $(git ls-files)
echo "+ npx cspell --no-progress --no-summary \$(git ls-files)"
npx cspell --no-progress --no-summary $(git ls-files)
for dictionary in .github/.cspell/*.txt; do
if [[ "${dictionary}" == .github/.cspell/project-dictionary.txt ]]; then