check / check (push) Waiting to run
script/fmt now runs golines -m 77 after gofmt, repeating golines until it changes nothing, since one pass can leave a line the next splits. script/fmt-check fails when either would change a file. script/bootstrap installs golines v0.13.0 with go install, pinned to its commit, and checks the installed version with go version -m. The tree is reformatted. The longer lines this makes are fixed by hand: nolint directives moved onto their own line above the statement, one string split, and 20 functions over funlen's 80 lines shortened or split, RunWAF and limitPercentages among them. Model: opus-5-5
58 lines
1.7 KiB
Bash
Executable File
58 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# script/fmt-check: check formatting (read-only): the Go code with
|
|
# gofmt and golines -m 77, the Markdown with prettier.
|
|
set -eu
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
|
|
# Must match the pin in script/bootstrap.
|
|
NODE_VERSION="22.17.0"
|
|
|
|
# script/bootstrap installs node and yarn under nvm and leaves neither
|
|
# on the PATH of the shell that called it, so resolve the pinned
|
|
# toolchain here the way bootstrap's own install step does. nvm is a
|
|
# bash script, hence the subshell.
|
|
run_yarn() {
|
|
if command -v yarn >/dev/null 2>&1; then
|
|
exec yarn "$@"
|
|
fi
|
|
if [ ! -s "$HOME/.nvm/nvm.sh" ]; then
|
|
echo "fmt-check: no yarn; run script/bootstrap first" >&2
|
|
exit 1
|
|
fi
|
|
exec bash -c '. "$HOME/.nvm/nvm.sh" && nvm use "$1" >/dev/null &&
|
|
shift && exec yarn "$@"' bash "$NODE_VERSION" "$@"
|
|
}
|
|
|
|
# The golines that script/bootstrap installed: go install puts it in
|
|
# GOBIN, or in GOPATH/bin when GOBIN is unset.
|
|
golines_path() {
|
|
gobin="$(go env GOBIN)"
|
|
golines="${gobin:-$(go env GOPATH)/bin}/golines"
|
|
if [ ! -x "$golines" ]; then
|
|
echo "fmt-check: no golines; run script/bootstrap first" >&2
|
|
exit 1
|
|
fi
|
|
echo "$golines"
|
|
}
|
|
|
|
main() {
|
|
cd "$ROOT"
|
|
golines="$(golines_path)"
|
|
unformatted="$(gofmt -l cmd internal)"
|
|
if [ -n "$unformatted" ]; then
|
|
echo "fmt-check: gofmt would change:" >&2
|
|
echo "$unformatted" >&2
|
|
exit 1
|
|
fi
|
|
unformatted="$("$golines" -m 77 -l cmd internal)"
|
|
if [ -n "$unformatted" ]; then
|
|
echo "fmt-check: golines -m 77 would change:" >&2
|
|
echo "$unformatted" >&2
|
|
exit 1
|
|
fi
|
|
run_yarn run prettier --check '**/*.md' --tab-width 4 --prose-wrap always
|
|
}
|
|
|
|
main "$@"
|