From cc6175d787bb0ff331b3f6a27dbcb9c47f671cd6 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 11 Jun 2026 10:06:20 +0100 Subject: [PATCH] Scope pre-commit golangci-lint to staged packages with bounded concurrency Lint only the packages containing staged .go files (falling back to ./... when none are staged) and cap golangci-lint concurrency/timeout via GOLANGCI_LINT_CONCURRENCY and GOLANGCI_LINT_TIMEOUT to keep the hook from exhausting resources on large trees. --- .husky/pre-commit | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index ceabe8e3e..901ca92e5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -68,7 +68,10 @@ gofmt -w -s . # Run Go linting (if golangci-lint is available) if command -v golangci-lint >/dev/null 2>&1; then echo "Running golangci-lint..." - golangci-lint run ./... + STAGED_GO_PKGS=$(git diff --cached --name-only | grep '\.go$' | xargs -I{} dirname {} 2>/dev/null | sort -u | sed 's|^|./|' | tr ' +' ' ') + 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 fi # Run frontend linting (if package.json has lint script)