mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-19 02:28:59 +00:00
Filter pre-commit golangci-lint to new issues only
The previous hook scoped lint to staged packages but still surfaced all pre-existing violations in those packages on every commit, which turned long-standing technical debt (errcheck on test mock helpers, dupl warnings on poll providers) into a per-commit blocker. Add --new-from-rev=HEAD so golangci-lint only reports issues introduced by the staged diff. Pre-existing violations on untouched lines are filtered out; new violations on changed lines still fail the commit. Override with GOLANGCI_LINT_NEW_FROM_REV (set to "" to lint the whole package, or to a base revision such as HEAD~5 to broaden the comparison window).
This commit is contained in:
parent
6c426d9f1a
commit
407024fdc7
1 changed files with 10 additions and 1 deletions
|
|
@ -134,7 +134,16 @@ if command -v golangci-lint >/dev/null 2>&1; then
|
|||
if [ -z "$STAGED_GO_PKGS" ]; then
|
||||
STAGED_GO_PKGS="./..."
|
||||
fi
|
||||
GOMAXPROCS="${GOMAXPROCS:-2}" golangci-lint run --concurrency "${GOLANGCI_LINT_CONCURRENCY:-2}" --timeout "${GOLANGCI_LINT_TIMEOUT:-5m}" $STAGED_GO_PKGS
|
||||
# Report only issues introduced by the staged diff. Pre-existing
|
||||
# violations in touched packages do not block new commits, but any
|
||||
# new violation on a changed line still fails the commit. Override
|
||||
# with GOLANGCI_LINT_NEW_FROM_REV=HEAD~5 etc, or "" to lint everything.
|
||||
NEW_FROM_REV="${GOLANGCI_LINT_NEW_FROM_REV-HEAD}"
|
||||
NEW_FROM_FLAG=""
|
||||
if [ -n "$NEW_FROM_REV" ]; then
|
||||
NEW_FROM_FLAG="--new-from-rev=$NEW_FROM_REV"
|
||||
fi
|
||||
GOMAXPROCS="${GOMAXPROCS:-2}" golangci-lint run --concurrency "${GOLANGCI_LINT_CONCURRENCY:-2}" --timeout "${GOLANGCI_LINT_TIMEOUT:-5m}" $NEW_FROM_FLAG $STAGED_GO_PKGS
|
||||
else
|
||||
echo "Skipping golangci-lint (no staged Go/module/linter changes)."
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue