From 80304b6f4171fc66d246bad8a319462db7bef499 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Tue, 6 Oct 2026 08:09:45 +0000 Subject: [PATCH] Make fmt-check check what fmt writes (closes #22) 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 --- README.md | 2 +- TODO.md | 4 ++++ script/fmt-check | 11 ++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5ad7d3..fc572fe 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Future improvements under consideration: * Issues / PRs: * Code must pass `make check`, which runs the tests and golangci-lint as phases of the `Dockerfile` (Docker is required) and checks formatting - with `gofmt`. + with `gofmt -s` and goimports. * No CLA; contributions are under WTFPL v2. --- diff --git a/TODO.md b/TODO.md index c24f343..0fbb313 100644 --- a/TODO.md +++ b/TODO.md @@ -24,6 +24,10 @@ Author are missing) # Completed Steps +* 2026-10-06: `script/fmt-check` checks what `script/fmt` writes: it + fails and lists the files when `gofmt -s` or goimports would change + one, so a file that passes `make check` no longer changes on the + next `make fmt` * 2026-10-06: canonical files re-vendored from `sneak/prompts` at `dd4027b`: `REPO_POLICIES.md` and `.editorconfig` added; `.dockerignore`, `.gitignore`, `.golangci.yml` and the workflow diff --git a/script/fmt-check b/script/fmt-check index b7438ef..91ebc00 100755 --- a/script/fmt-check +++ b/script/fmt-check @@ -7,10 +7,15 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" main() { cd "$ROOT" - files="$(gofmt -l .)" + # 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 "gofmt: files not formatted:" >&2 - echo "$files" >&2 + echo "files that make fmt would change:" >&2 + echo "$files" | sort -u >&2 exit 1 fi } -- 2.54.0