From 8af6104454344ee44a9d3dd1d9fdcf06369443c5 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 2 Jul 2026 09:06:21 +0200 Subject: [PATCH] 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) --- .github/workflows/ci.yml | 5 +++++ .golangci.yml | 4 +++- Makefile | 1 + justfile | 1 + scripts/gofumpt-check.sh | 22 ++++++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 scripts/gofumpt-check.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f7c1d2d2..4e7538b0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.golangci.yml b/.golangci.yml index c13f7b9f3..c46e438ac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/Makefile b/Makefile index 6b51d5250..10bea092a 100644 --- a/Makefile +++ b/Makefile @@ -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. diff --git a/justfile b/justfile index 7909cb2d6..f9351732a 100644 --- a/justfile +++ b/justfile @@ -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" diff --git a/scripts/gofumpt-check.sh b/scripts/gofumpt-check.sh new file mode 100755 index 000000000..ff251306c --- /dev/null +++ b/scripts/gofumpt-check.sh @@ -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