chore: update golangci-lint config#3306
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe Changesgolangci-lint configuration rewrite
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.golangci.yml:
- Line 3: The golangci-lint config and toolchain are mismatched, and the
exclusion patterns using trailing $ are not excluding directory contents. Update
the paths exclusions in the golangci-lint config to use directory-prefix entries
for third_party, builtin, and examples, and migrate the lint tool installation
to the /v2 module path in both the Makefile and tools/linters/go.mod. Keep the
version: "2" config aligned with the v2 golangci-lint module and verify the
updated exclusions still apply through the existing golangci-lint settings.
- Around line 113-116: The exclusion patterns in the golangci config only match
the exact directory names, so nested files under those directories are still
linted. Update the path regexes in the duplicated paths sections of the
configuration to match the directory as a path component, using the existing
exclusion entries for third_party, builtin, and examples as the anchors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 530f71e2-c681-4225-afed-72780bc8cc2f
📒 Files selected for processing (1)
.golangci.yml
| @@ -1,65 +1,52 @@ | |||
| # Originally copied from github.com/stackrox/stackrox, and regularly kept in-sync manually. | |||
|
|
|||
| version: "2" | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Config version:"
sed -n '1,6p' .golangci.yml
echo
echo "Pinned golangci-lint module(s):"
fd -a '^go\.mod$' tools 2>/dev/null | xargs -r rg -n 'github\.com/golangci/golangci-lint'
echo
echo "Makefile golangci-lint install/run entrypoints:"
rg -n -C2 'github\.com/golangci/golangci-lint(/v2)?/cmd/golangci-lint|\$\(GOLANGCILINT_BIN\) run' MakefileRepository: stackrox/scanner
Length of output: 1251
🏁 Script executed:
# Example of incorrect vs correct behavior
# Incorrect: matches "third_party" but not "third_party/file.go"
# Correct: matches "third_party/" and "third_party/file.go"
third_party/Repository: stackrox/scanner
Length of output: 201
Update exclusion path patterns and migrate to the v2 toolchain.
The configuration uses version: "2", but the Makefile installs golangci-lint from the v1 module path (github.com/golangci/golangci-lint at v1.64.8). While v1.64.8 detects v2 configs, consistency requires migrating the tool installation to github.com/golangci/golangci-lint/v2.
More critically, the exclusion patterns (e.g., third_party$) use a trailing $ anchor, which fails to exclude files inside those directories. In golangci-lint, the paths exclusion list treats trailing slashes as directory prefixes. Update the patterns (lines 114–116 and 127–129) to:
- third_party/- builtin/- examples/
Also update the v1 install command in the Makefile and tools/linters/go.mod to use the /v2 module path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.golangci.yml at line 3, The golangci-lint config and toolchain are
mismatched, and the exclusion patterns using trailing $ are not excluding
directory contents. Update the paths exclusions in the golangci-lint config to
use directory-prefix entries for third_party, builtin, and examples, and migrate
the lint tool installation to the /v2 module path in both the Makefile and
tools/linters/go.mod. Keep the version: "2" config aligned with the v2
golangci-lint module and verify the updated exclusions still apply through the
existing golangci-lint settings.
| paths: | ||
| - third_party$ | ||
| - builtin$ | ||
| - examples$ |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python - <<'PY'
import re
current = [r"third_party$", r"builtin$", r"examples$"]
proposed = [r"(^|/)third_party(/|$)", r"(^|/)builtin(/|$)", r"(^|/)examples(/|$)"]
paths = [
"third_party/foo.go",
"pkg/third_party/foo.go",
"builtin/foo.go",
"examples/foo.go",
]
for path in paths:
print(path)
print(" current:", any(re.search(p, path) for p in current))
print(" proposed:", any(re.search(p, path) for p in proposed))
PY
for d in third_party builtin examples; do
echo
echo "Sample files under $d, if present:"
fd . "$d" -t f -d 2 2>/dev/null | head -5 || true
doneRepository: stackrox/scanner
Length of output: 491
Fix path exclusions to correctly exclude directory trees
The current regex patterns third_party$, builtin$, and examples$ in .golangci.yml are insufficient because they only match paths ending exactly at the directory name. Consequently, files inside these directories (e.g., third_party/foo.go) are not excluded and will still be processed by linters/formatters.
Update the patterns in both locations (lines 113–116 and 126–129) to match the directory as a path component.
Suggested update
paths:
- - third_party$
- - builtin$
- - examples$
+ - '(^|/)third_party(/|$)'
+ - '(^|/)builtin(/|$)'
+ - '(^|/)examples(/|$)'
@@
paths:
- - third_party$
- - builtin$
- - examples$
+ - '(^|/)third_party(/|$)'
+ - '(^|/)builtin(/|$)'
+ - '(^|/)examples(/|$)'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| paths: | |
| - third_party$ | |
| - builtin$ | |
| - examples$ | |
| paths: | |
| - '(^|/)third_party(/|$)' | |
| - '(^|/)builtin(/|$)' | |
| - '(^|/)examples(/|$)' |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.golangci.yml around lines 113 - 116, The exclusion patterns in the golangci
config only match the exact directory names, so nested files under those
directories are still linted. Update the path regexes in the duplicated paths
sections of the configuration to match the directory as a path component, using
the existing exclusion entries for third_party, builtin, and examples as the
anchors.
97bc271 to
e3ee48e
Compare
Updates .golangci.yml with https://github.com/stackrox/stackrox/blob/d5fcd2f1740ad84ff88a1e4155ca9636df87cd47/.golangci.yml.
The impetus for this change is the OOM failures during some GitHub Actions. Example: https://github.com/stackrox/scanner/actions/runs/28221635477/job/83604060577?pr=3153