Update tools/tidy.sh

This commit is contained in:
Taiki Endo
2023-04-05 22:47:02 +09:00
parent 4d6942468f
commit 2402df67ca
3 changed files with 40 additions and 17 deletions

View File

@@ -67,6 +67,7 @@ openwrt
riscv
softfloat
sparcv
spirv
thumbeb
thumbebv
thumbv
@@ -89,12 +90,14 @@ bools
builtins
bytecount
canonicalize
concat
consts
ctypes
dealloc
deque
docsrs
doctest
doctests
hasher
impls
inlateout
@@ -148,6 +151,7 @@ powerset
proto
ranlib
readelf
shellcheckrc
SIGABRT
SIGILL
SIGINT

View File

@@ -1,5 +1,4 @@
binstall
bytecodealliance
coreutils
distro
doas
@@ -7,21 +6,15 @@ dprint
enablerepo
epel
grcov
jfrimmel
koalaman
libc
linkcheck
mdbook
microdnf
mvdan
nextest
protobuf
protoc
protocolbuffers
pwsh
quickinstall
rockylinux
rustwasm
shellcheck
shfmt
udeps

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
# shellcheck disable=SC2046
set -euo pipefail
IFS=$'\n\t'
@@ -33,6 +34,9 @@ check_diff() {
fi
fi
}
info() {
echo >&2 "info: $*"
}
warn() {
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
echo "::warning::$*"
@@ -171,7 +175,9 @@ fi
# Spell check (if config exists)
if [[ -f .cspell.json ]]; then
if type -P npm &>/dev/null; then
has_rust=''
if [[ -n "$(git ls-files '*Cargo.toml')" ]]; then
has_rust='1'
dependencies=''
for manifest_path in $(git ls-files '*Cargo.toml'); do
if [[ "${manifest_path}" != "Cargo.toml" ]] && ! grep -Eq '\[workspace\]' "${manifest_path}"; then
@@ -179,24 +185,27 @@ if [[ -f .cspell.json ]]; then
fi
metadata=$(cargo metadata --format-version=1 --all-features --no-deps --manifest-path "${manifest_path}")
for id in $(jq <<<"${metadata}" '.workspace_members[]'); do
dependencies+=$'\n'
dependencies+=$(jq <<<"${metadata}" ".packages[] | select(.id == ${id})" | jq -r '.dependencies[].name')
dependencies+="$(jq <<<"${metadata}" ".packages[] | select(.id == ${id})" | jq -r '.dependencies[].name')"$'\n'
done
done
# shellcheck disable=SC2001
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
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
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)
# TODO: handle SIGINT
echo "${config_old}" >.cspell.json
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 $'\n'"${words}" >>.github/.cspell/rust-dependencies.txt
if [[ -n "${dependencies_words:-}" ]]; then
echo $'\n'"${dependencies_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
@@ -204,8 +213,11 @@ EOF
fi
echo "+ npx cspell --no-progress --no-summary \$(git ls-files)"
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"
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
continue
@@ -218,6 +230,20 @@ EOF
echo "======================================="
fi
done
# Make sure the project-specific dictionary does not contain unused words.
unused=''
for word in $(grep -v '//.*' .github/.cspell/project-dictionary.txt || 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"
echo "======================================="
echo -n "${unused}"
echo "======================================="
fi
else
warn "'npm' is not installed"
fi