Check gofumpt formatting with the pinned version in CI and lint

golangci-lint bundles gofumpt v0.8.0, which formats code differently
from the v0.9.2 we pin in go.mod. Enforcing formatting through
golangci-lint may therefore disagree with `just format`.

Remove gofumpt from golangci-lint's formatters and instead run the
pinned `go tool gofumpt` as a standalone check via a new
scripts/gofumpt-check.sh, wired into CI, `just lint`, and `make lint`.
goimports stays in golangci-lint; it's stable across versions and
nothing runs a competing copy of it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-07-02 11:16:53 +02:00
co-authored by Claude Opus 4.8
parent 9882e4a03e
commit 8af6104454
5 changed files with 32 additions and 1 deletions
+5
View File
@@ -167,7 +167,12 @@ jobs:
uses: actions/setup-go@v6
with:
go-version: 1.25.x
- name: Check formatting
run: ./scripts/gofumpt-check.sh
- name: Lint
# Run even if the formatting check failed, so that both sets of
# problems are reported in a single CI run.
if: ${{ !cancelled() }}
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
with:
# If you change this, make sure to also update scripts/golangci-lint-shim.sh
+3 -1
View File
@@ -102,7 +102,9 @@ linters:
- vendor/
formatters:
enable:
- gofumpt
# gofumpt is intentionally not listed here: golangci-lint bundles its own
# gofumpt version, which drifts from the one we pin in go.mod. We run that
# pinned version separately via scripts/gofumpt-check.sh instead.
- goimports
exclusions:
generated: lax
+1
View File
@@ -40,6 +40,7 @@ format:
.PHONY: lint
lint:
./scripts/gofumpt-check.sh
./scripts/golangci-lint-shim.sh run
# For more details about integration test, see https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md.
+1
View File
@@ -37,6 +37,7 @@ format:
go tool gofumpt -l -w .
lint:
./scripts/gofumpt-check.sh
./scripts/golangci-lint-shim.sh run
e2e-test-command := "go test pkg/integration/clients/*.go"
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
# Checks that all Go files are gofumpt-formatted, and fails if any aren't.
# Used by `just lint`, `make lint`, and CI. We run gofumpt with the version
# pinned in go.mod (via `go tool`) rather than the one bundled with
# golangci-lint, so that formatting is identical across all of them and the
# editor.
set -e
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
repo_root=$(dirname "$script_dir")
cd "$repo_root"
unformatted=$(go tool gofumpt -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted correctly:"
echo "$unformatted"
echo "Run 'just format' (or 'make format') and commit the result."
exit 1
fi