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.
This commit is contained in:
rcourtman 2026-06-11 10:06:20 +01:00
parent b47a81173f
commit cc6175d787

View file

@ -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)