diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 661445f9a..16b4ba451 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10ce06949..fc8edcbea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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]