Skip to content

[linter-miner] Add filepath.WalkDir preference linter - #75956

Merged
pelikhan merged 4 commits into
mainfrom
copilot/linter-mineradd-filepath-walkdir-preference-linter
Nov 8, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/linter-mineradd-filepath-walkdir-preference-linter

Conversation

Copilot AI commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

filepath.Walk can perform unnecessary filesystem metadata work compared with filepath.WalkDir. This adds an advisory analyzer that recommends filepath.WalkDir for standard-library filepath.Walk calls.

  • Detection: Resolve calls through type information, including import aliases, dot imports, parenthesized calls, and local function aliases. Skip generated files and honor nolint.
  • Registration: Add analysistest coverage and document the analyzer; keep it advisory until existing call sites are remediated.
filepath.Walk(root, visit)   // reported
filepath.WalkDir(root, visit) // preferred

Copilot AI changed the title [WIP] Add filepath.WalkDir preference linter [linter-miner] Add filepath.WalkDir preference linter Nov 8, 2026
Copilot AI requested a review from gh-aw-bot November 8, 2026 20:38
@pelikhan
pelikhan marked this pull request as ready for review November 8, 2026 21:20
Copilot AI adaptive review requested due to automatic review settings November 8, 2026 21:20
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

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.

Generated from PR Specification Reviewer · gpt56 · ~1 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75956

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_no_action

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.

Generated from PR Code Quality Reviewer · gpt56 · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

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.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #75956

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Warning

The push_to_pull_request_branch operation failed: Cannot verify branch protection rules for "copilot/linter-mineradd-filepath-walkdir-preference-linter": Resource not accessible by integration - https://docs.github.com/rest/branches/branch-protection\#get-branch-protection. Reading classic branch protection requires a GitHub App installation token or fine-grained PAT with Administration: read repository permission; GITHUB_TOKEN cannot provide this permission. Push blocked to prevent accidental writes to protected branches.. The code changes were not applied.

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (127 added lines under pkg/, above the 100-line threshold) but does not have a linked Architecture Decision Record (ADR). The linked issue #75936 does not contain one either.

📄 Draft ADR committed: docs/adr/75956-add-filepath-walkdir-preference-linter.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff

  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered

  3. Commit the finalized ADR to docs/adr/ on your branch

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-75956: Add an Advisory Linter Preferring filepath.WalkDir (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

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 Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.Walk calls 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")

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: WalkDir callbacks receive fs.DirEntry, not os.FileInfo, so the message should say so; 31 existing pkg/cli sites will need d.Info() rather than a mechanical swap.

Positive Highlights

  • ✅ Type-resolved detection via astutil.PackageCall rather than syntactic name matching.
  • ✅ Generated-file, test-file, and nolint handling 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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/filepathwalkpreferwalkdir/testdata/src/filepathwalkpreferwalkdir/walk.go:15): [/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. - [linter-miner] Add filepath.WalkDir preference linter #75956 (comment)
  3. Review (pkg/linters/filepathwalkpreferwalkdir/filepathwalkpreferwalkdir.go:41): [/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. - [linter-miner] Add filepath.WalkDir preference linter #75956 (comment)
  4. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42524677955/job/128867125383.

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
Sous-chef requested-work: 2c7063152006f3d763d598cbe8126840f43180af94be580e3b3dbf560f602a90 4aef0f9ec14242200e3933e12e0123d456ba9f711ae9ff62aa62aa786422eed4 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: 258988d1a941efeb3b76f289e546bfa5b5d411d2efc741772c26c35cc966c487

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~5 AIC · ⌖ ~13 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Work is starting.

Sous-chef requested-head: c8ce38b
Sous-chef requested-work: 2c7063152006f3d763d598cbe8126840f43180af94be580e3b3dbf560f602a90 4aef0f9ec14242200e3933e12e0123d456ba9f711ae9ff62aa62aa786422eed4 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: 258988d1a941efeb3b76f289e546bfa5b5d411d2efc741772c26c35cc966c487

Copilot AI and others added 2 commits November 8, 2026 21:52
@pelikhan
pelikhan merged commit fdad7eb into main Nov 8, 2026
46 checks passed
@pelikhan
pelikhan deleted the copilot/linter-mineradd-filepath-walkdir-preference-linter branch November 8, 2026 22:37
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[linter-miner] Add filepath.WalkDir preference linter

4 participants