Skip to content

ci: add pre-commit config to enforce make lint-fix#26510

Open
aljo242 wants to merge 1 commit into
mainfrom
chore/add-precommit-lint-fix
Open

ci: add pre-commit config to enforce make lint-fix#26510
aljo242 wants to merge 1 commit into
mainfrom
chore/add-precommit-lint-fix

Conversation

@aljo242

@aljo242 aljo242 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds .pre-commit-config.yaml with a single local hook that runs make lint-fix before every commit
  • Catches gci import ordering, gofumpt, and staticcheck issues locally before they hit CI
  • Zero new dependencies — uses the existing make lint-fix target

Usage

# Install once
pre-commit install

# Run manually on all files
pre-commit run --all-files

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

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
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🔒 WARNING: unsigned commits detected

This pull request contains 1 commit(s) without a verified signature.

How to fix:

  1. Set up commit signing (GPG or SSH).
  2. Amend/rebase so every commit in this PR is verified-signed.
  3. Push the updated branch and open a new PR, or ask a maintainer to reopen once fixed.

Docs: https://docs.github.com/authentication/managing-commit-signature-verification

Unsigned commits:

  • bb74588 — ci: add pre-commit config to enforce make lint-fix

@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a .pre-commit-config.yaml with a single local hook that runs make lint-fix before every commit, aiming to catch import-ordering, formatting, and staticcheck issues locally before they reach CI.

  • The hook invokes make lint-fix, which ultimately calls ./scripts/go-lint-all.bash --fix without the LINT_DIFF guard, linting every Go module in the entire monorepo on each commit — the same workload as the 15-minute CI lint job. Setting env: [LINT_DIFF=1] in the hook would scope linting to only the directories containing changed files, which the script already supports.
  • always_run: true with no files pattern means the full lint pipeline also fires on commits that touch only docs, YAML, or proto files; adding files: \.go$ and removing always_run: true would let pre-commit skip the hook when no Go files are staged.

Confidence Score: 3/5

The 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 (make lint-fix) invokes go-lint-all.bash over every Go module in the repo without diff-scoping, mirroring the full 15-minute CI lint job. On every commit — including docs-only changes — this penalty applies because always_run: true overrides any file-based skipping. A hook that costs several minutes per commit in a busy monorepo is routinely disabled, which would entirely defeat the stated goal of catching lint failures locally before CI.

.pre-commit-config.yaml — the only changed file; the entry and always_run settings need adjustment before the hook is practical to use.

Important Files Changed

Filename Overview
.pre-commit-config.yaml Adds a pre-commit hook running full make lint-fix (all modules, no diff scoping) on every commit; the missing LINT_DIFF scoping and unconditional always_run: true make the hook impractically slow for a monorepo of this size.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[git commit] --> B{pre-commit hook triggered}
    B --> C[make lint-fix]
    C --> D[make lint-install\ngo install golangci-lint]
    D --> E{LINT_DIFF set?}
    E -- No current config --> F[go-lint-all.bash --fix\nwalks ALL go.mod files\nin entire repo]
    E -- With LINT_DIFF=1 --> G[go-lint-all.bash --fix\nlints only changed\ndirectories]
    F --> H{Files modified by lint-fix?}
    G --> H
    H -- Yes --> I[Hook exits non-zero\nCommit aborted\nUser must git add fixes and retry]
    H -- No --> J[Hook exits 0\nCommit proceeds]
Loading

Reviews (1): Last reviewed commit: "ci: add pre-commit config to enforce mak..." | Re-trigger Greptile

Comment thread .pre-commit-config.yaml
Comment on lines +6 to +9
entry: make lint-fix
language: system
pass_filenames: false
always_run: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment thread .pre-commit-config.yaml
entry: make lint-fix
language: system
pass_filenames: false
always_run: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant