fix: detect Go version mismatch in pre-commit hook before golangci-lint panics (bd-66nc)

When golangci-lint is built with an older Go than the project requires
(e.g. go1.25 binary vs go1.26 project), its internal go/types package
panics on newer syntax. Add a version check to .githooks/pre-commit that
compares golangci-lint built-with Go version against go.mod and exits
with a clear error message instead of a cryptic panic.

Also bump .pre-commit-config.yaml golangci-lint from v2.1.6 to v2.10.1.

Executed-By: beads/refinery
Rig: beads
Role: refinery
This commit is contained in:
quartz 2026-03-02 18:46:27 -08:00 • committed by Steve Yegge
commit 89b97da5ea
2 changed files with 21 additions and 1 deletions

View file

@ -17,6 +17,26 @@ if ! command -v golangci-lint &>/dev/null; then
exit 1
fi
# Check for Go version mismatch that causes golangci-lint panics.
# When golangci-lint is built with an older Go than the project requires,
# its internal go/types package can panic on newer syntax/types.
lint_go_ver=$(golangci-lint version 2>&1 | sed -n 's/.*built with go\([0-9]*\.[0-9]*\).*/\1/p')
proj_go_ver=$(sed -n 's/^go \([0-9]*\.[0-9]*\).*/\1/p' go.mod)
if [ -n "$lint_go_ver" ] && [ -n "$proj_go_ver" ]; then
lint_major=${lint_go_ver%%.*}
lint_minor=${lint_go_ver#*.}
proj_major=${proj_go_ver%%.*}
proj_minor=${proj_go_ver#*.}
if [ "$lint_major" -lt "$proj_major" ] 2>/dev/null || \
{ [ "$lint_major" -eq "$proj_major" ] && [ "$lint_minor" -lt "$proj_minor" ]; } 2>/dev/null; then
echo "pre-commit: golangci-lint was built with go${lint_go_ver} but project requires go${proj_go_ver}."
echo " This version mismatch causes panics during type checking."
echo " Fix: brew upgrade golangci-lint"
echo " Or: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
exit 1
fi
fi
# Auto-format and re-stage
echo "$staged_go_files" | xargs gofmt -w
echo "$staged_go_files" | xargs git add

View file

@ -1,6 +1,6 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v2.1.6
rev: v2.10.1
hooks:
- id: golangci-lint
args: [--timeout=5m]