Skip to content

Detect typed map[string]bool set aliases in short declarations - #51303

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-seenmapbool-ast-check
Aug 8, 2026
Merged

Detect typed map[string]bool set aliases in short declarations#51303
pelikhan merged 2 commits into
mainfrom
copilot/fix-seenmapbool-ast-check

Conversation

CopilotAI commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

seenmapbool only considered := declarations when the RHS was a literal make(map[string]bool) or composite literal. Typed maps returned by helpers or copied from variables were silently skipped.

  • Candidate detection

    • Use the declared identifier type as the sole := eligibility check.
    • Remove redundant RHS AST-shape checks.
  • Regression coverage

    • Diagnose helper-returned maps.
    • Diagnose maps copied from map[string]bool parameters.
seen:=getSeenMap() // now diagnosedseen["x"] =trueseen:=other// now diagnosedseen["x"] =true

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix seenmapbool to correctly detect map[string]bool variablesDetect typed map[string]bool set aliases in short declarationsAug 8, 2026
CopilotAI requested a review from pelikhanAugust 8, 2026 04:41
@github-actions

Copy link
Copy Markdown
Contributor

Great work! 🎉 This fix to the seenmapbool linter properly addresses the under-detection gap in issue #51300.

The change is well-scoped — removing the redundant RHS AST-shape check and relying solely on the type system to identify eligible map[string]bool variables, just like the var branch already does. The regression test coverage (helper-returned maps and variable copies) is exactly what was needed.

The simplification from 38 deleted lines and 2 added lines shows this was a clean fix that removed unnecessary complexity rather than adding new logic. The diff balances well with the test expansion.

This PR looks ready for review. Nice work aligning the := and var candidate detection paths!

Generated by ✅ Contribution Check · auto · 58.8 AIC · ⌖ 3.48 AIC · ⊞ 8.7K ·

@pelikhan
pelikhan marked this pull request as ready for review August 8, 2026 05:53
CopilotAI balanced review requested due to automatic review settings August 8, 2026 05:53
@pelikhan
pelikhan merged commit 51c8a62 into mainAug 8, 2026
1 check passed
@pelikhan
pelikhan deleted the copilot/fix-seenmapbool-ast-check branch August 8, 2026 05:53

CopilotAI 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

Updates seenmapbool to detect typed map[string]bool values initialized from helpers or variables.

Changes:

  • Uses identifier types instead of RHS syntax for candidate detection.
  • Removes obsolete AST-shape helpers.
  • Adds regression cases for helper returns and map copies.
Show a summary per file
FileDescription
pkg/linters/seenmapbool/seenmapbool.goBroadens short-declaration candidate detection.
pkg/linters/seenmapbool/testdata/src/seenmapbool/seenmapbool.goAdds regression coverage for newly detected patterns.

Review details

Tip

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

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

continue
}
if isMapStringBool(pass.TypesInfo.TypeOf(ident)) && isMapStringBoolExpr(stmt.Rhs[i]) {
if isMapStringBool(pass.TypesInfo.TypeOf(ident)) {
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

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

Labels

None yet

Projects

None yet

3 participants

@pelikhan