Skip to content

hardcodedfilepath: include same-package unexported consts in reuse suggestions - #52948

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-hardcodedfilepath-const-filter
Aug 15, 2026
Merged

hardcodedfilepath: include same-package unexported consts in reuse suggestions#52948
pelikhan merged 4 commits into
mainfrom
copilot/fix-hardcodedfilepath-const-filter

Conversation

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

collectKnownPathConsts applied an exported-only filter to both imported constants and current-package constants. That caused same-package duplicates of unexported path constants to be misdiagnosed as “extract a new constant” instead of “reuse existing constant”.

  • Behavioral fix: scope-aware constant visibility

    • Updated collectKnownPathConsts to treat visibility differently by source:
      • current package scope: include exported + unexported constants
      • imported *constants* packages: keep exported-only filtering
  • Regression coverage: same-package unexported reuse path

    • Added analyzer testdata case with a second use of an unexported local path constant.
    • Expected diagnostic now asserts reuse of localPathConst (not extraction of a new constant).
// current package constants: no exported-only gate
addConst(c, "", name, false)

// imported constants packages: exported-only gate preserved
addConst(c, alias, name, true)

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 7.49 AIC · ⌖ 5.77 AIC · ⊞ 8.7K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix hardcodedfilepath exported-only filter for unexported constants hardcodedfilepath: include same-package unexported consts in reuse suggestions Aug 15, 2026
Copilot AI requested a review from pelikhan August 15, 2026 18:59
@pelikhan
pelikhan marked this pull request as ready for review August 15, 2026 19:07
Copilot AI balanced review requested due to automatic review settings August 15, 2026 19:07

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.

Pull request overview

Fixes scope-aware constant reuse suggestions in the hardcodedfilepath analyzer.

Changes:

  • Includes unexported constants from the current package.
  • Preserves exported-only filtering for imported constants.
  • Adds regression coverage for local unexported constant reuse.
Show a summary per file
File Description
pkg/linters/hardcodedfilepath/hardcodedfilepath.go Applies source-specific visibility filtering.
pkg/linters/hardcodedfilepath/testdata/src/hardcodedfilepath/hardcodedfilepath.go Tests reuse of an unexported local constant.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot All checks are green, but this PR still needs a maintainer-ready finish.

Please refresh the branch if needed and run the pr-finisher skill so the PR is ready for investigation.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 7.49 AIC · ⌖ 5.77 AIC · ⊞ 8.7K ·
Comment /souschef to run again

…filepath-const-filter

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot All checks are green, but this PR still needs a maintainer-ready finish.

Please refresh the branch if needed and run the pr-finisher skill so the PR is ready for investigation....

Refreshed the branch with current main in 59cf9b9 and completed the pr-finisher validation pass (make fmt, make lint, make test, make recompile, and make agent-report-progress). No unresolved review threads remain.

Copilot AI requested a review from gh-aw-bot August 15, 2026 19:47
@pelikhan
pelikhan merged commit 470cef8 into main Aug 15, 2026
@pelikhan
pelikhan deleted the copilot/fix-hardcodedfilepath-const-filter branch August 15, 2026 19:48
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.0

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

Labels

None yet

Projects

None yet

4 participants