ci: add pre-commit config to enforce make lint-fix#26510
Conversation
Adds a local pre-commit hook that runs `make lint-fix` before every commit. This catches gci import ordering, gofumpt formatting, and staticcheck issues locally before they reach CI. Install once with: pre-commit install Run manually with: pre-commit run --all-files Issue: N/A
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Docs: https://docs.github.com/authentication/managing-commit-signature-verification Unsigned commits:
|
Greptile SummaryThis PR adds a
Confidence Score: 3/5The file itself is opt-in tooling and safe to merge, but as written the hook runs a full monorepo lint on every commit, making it too slow for practical use and likely to be disabled by contributors. The hook's entry point ( .pre-commit-config.yaml — the only changed file; the Important Files Changed
|
| entry: make lint-fix | ||
| language: system | ||
| pass_filenames: false | ||
| always_run: true |
There was a problem hiding this comment.
Full-repo lint on every commit is impractically slow
make lint-fix calls ./scripts/go-lint-all.bash --fix without LINT_DIFF set, which means it walks every go.mod in the repo and runs golangci-lint on every module—mirroring the full CI lint job (15-minute timeout). Running this on every commit will make the hook a pain point that developers quickly disable. The script already supports scoped linting: setting LINT_DIFF=1 limits it to only the directories containing changed .go files. Adding env: [LINT_DIFF=1] to the hook entry would keep commit latency acceptable while still catching the most common issues before they reach CI.
| entry: make lint-fix | ||
| language: system | ||
| pass_filenames: false | ||
| always_run: true |
There was a problem hiding this comment.
always_run: true triggers lint even for non-Go commits
With always_run: true and no files pattern, the hook fires on every staged-file set—including commits that touch only docs, YAML, or proto files. Combined with the already-expensive full-repo lint, this multiplies the overhead for non-Go changes. Removing always_run: true and adding files: \.go$ would let pre-commit skip the hook when no Go files are staged (since pass_filenames: false still respects file-based hook skipping).
Summary
.pre-commit-config.yamlwith a single local hook that runsmake lint-fixbefore every commitmake lint-fixtargetUsage
Why
Several recent PRs and commits have had lint failures caught by CI that a pre-commit hook would have caught locally, requiring extra fix-up commits. This hook closes that loop.
Issue: N/A