check / check (push) Successful in 1m52s
script/fmt writes with gofmt -s and goimports, but script/fmt-check only ran gofmt -l. A file that gofmt -s would simplify, or whose imports goimports would regroup, passed make check and then changed on the next make fmt. script/fmt-check now runs gofmt -s -l and goimports -l, prints each file either would change once, and fails. It puts Go's bin directory on PATH first, as script/fmt does, so it runs the goimports that script/bootstrap installs. The README line on what make check runs now names both formatters. Model: opus-5-5
24 lines
598 B
Bash
Executable File
24 lines
598 B
Bash
Executable File
#!/bin/sh
|
|
# script/fmt-check: check formatting (read-only). Same scope as
|
|
# script/fmt, but fails instead of writing.
|
|
set -eu
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
|
|
main() {
|
|
cd "$ROOT"
|
|
# script/bootstrap installs goimports into Go's bin directory, which
|
|
# need not be on PATH.
|
|
gobin="$(go env GOBIN)"
|
|
[ -n "$gobin" ] || gobin="$(go env GOPATH)/bin"
|
|
PATH="$gobin:$PATH"
|
|
files="$(gofmt -s -l .; goimports -l .)"
|
|
if [ -n "$files" ]; then
|
|
echo "files that make fmt would change:" >&2
|
|
echo "$files" | sort -u >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
main "$@"
|