Repository navigation
[linter-miner] Add filepath.WalkDir preference linter - #75956
Conversation
Co-authored-by: gh-aw-bot <[email protected]>
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (127 added lines under 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. ❓ Why ADRs Matter
ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
🟡 Changes recommended
The analyzer reports zero-hit Walk calls when coverage profiling is enabled and lacks a hot-threshold option, violating the documented coverage-aware reporting convention.
1 open issue
1 file not reviewed
pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/generated.go: Generated file
What changed in this PR
Adds filepathwalkpreferwalkdir to gh-aw’s custom Go analyzers, recommending filepath.WalkDir to avoid unnecessary filesystem metadata work. The rule remains advisory while existing call sites are migrated.
Changes:
- Detects standard-library
filepath.Walkcalls through type information, including aliases and parenthesized calls. - Adds fixtures for detection, suppression, generated-file skipping, and unrelated calls.
- Registers and documents the analyzer without enabling CI enforcement.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to documentation contract checks. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/README.md |
Documents the rule and its public package. |
pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/walk.go |
Covers call forms, suppression, and negative cases. |
pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/generated.go |
Checks generated-file skipping. |
pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/dotimport.go |
Covers dot-imported calls. |
pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/aliased.go |
Covers aliased imports. |
pkg/linters/filepathwalkpreferwalkdir/filepathwalkpreferwalkdir.go |
Implements detection and diagnostics. |
pkg/linters/filepathwalkpreferwalkdir/filepathwalkpreferwalkdir_test.go |
Validates the analyzer and runs fixtures. |
pkg/linters/doc.go |
Updates the analyzer catalog and count. |
pkg/linters/doc_sync_test.go |
Records deferred CI enforcement. |
Review effort: Balanced (auto)
| nolint.HasDirectiveForLinter(pos, noLintIndex, linterName) { | ||
| return | ||
| } | ||
| pass.ReportRangef(call, "filepath.Walk is less efficient than filepath.WalkDir; prefer filepath.WalkDir") |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /codebase-design. Detection is sound: local probes confirmed that qualified, aliased, dot-imported, parenthesized, and unshadowed function-variable calls are reported, and that a reassigned alias is not. Tests pass and the registry/doc counts are consistent (92→93, 91→92). Two non-blocking suggestions are posted inline.
📋 Key Themes & Highlights
Key Themes
- Missing regression fixture: the reassigned-alias guard is the subtlest branch but is untested.
- Migration hint:
WalkDircallbacks receivefs.DirEntry, notos.FileInfo, so the message should say so; 31 existingpkg/clisites will needd.Info()rather than a mechanical swap.
Positive Highlights
- ✅ Type-resolved detection via
astutil.PackageCallrather than syntactic name matching. - ✅ Generated-file, test-file, and
nolinthandling mirror sibling analyzers. - ✅ Staying advisory (
notYetEnforced) avoids breaking CI on existing call sites.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 6.3K
Comment /matt to run again
|
|
||
| func functionAlias(root string) { | ||
| walk := filepath.Walk | ||
| walk(root, nil) // want "filepath.Walk is less efficient" |
There was a problem hiding this comment.
[/tdd] The alias-reassignment guard in packageFunctionAlias (the mutable flag in internal/astutil) has no fixture. A local probe confirmed a reassigned alias is correctly not reported, but nothing in this PR locks that in, and it is the subtlest branch of the new detection. Add a no-want case.
💡 Suggested test
func reassignedAlias(root string) {
walk := filepath.Walk
walk = func(string, filepath.WalkFunc) error { return nil }
walk(root, nil) // no want: alias no longer refers to filepath.Walk
}Without this, a future change to alias tracking could start producing false positives silently.
@copilot please address this.
| nolint.HasDirectiveForLinter(pos, noLintIndex, linterName) { | ||
| return | ||
| } | ||
| pass.ReportRangef(call, "filepath.Walk is less efficient than filepath.WalkDir; prefer filepath.WalkDir") |
There was a problem hiding this comment.
[/codebase-design] The message is not actionable as a migration hint. filepath.WalkDir passes an fs.DirEntry instead of os.FileInfo, so the 31 hits in pkg/cli (for example compile_watch.go:82, whose callback is declared info os.FileInfo) cannot be swapped mechanically. Any info.Size() or info.ModTime() use needs d.Info(). The existing want regex still matches if the message is extended.
💡 Suggested message
pass.ReportRangef(call, "filepath.Walk is less efficient than filepath.WalkDir; prefer filepath.WalkDir (its callback receives fs.DirEntry, so use d.Info() for metadata)")This keeps the advisory from pushing authors toward a rewrite that does not compile.
@copilot please address this.
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: c8ce38b
|
Work is starting. Sous-chef requested-head: c8ce38b |
…dd-filepath-walkdir-preference-linter Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |

filepath.Walkcan perform unnecessary filesystem metadata work compared withfilepath.WalkDir. This adds an advisory analyzer that recommendsfilepath.WalkDirfor standard-libraryfilepath.Walkcalls.nolint.