Skip to content

fix(seenmapbool): treat non-true values in declaration-site composite literals as non-set maps - #51514

Merged
pelikhan merged 2 commits into
mainfrom
copilot/seenmapbool-fix-composite-literal-checks
Aug 9, 2026
Merged

fix(seenmapbool): treat non-true values in declaration-site composite literals as non-set maps#51514
pelikhan merged 2 commits into
mainfrom
copilot/seenmapbool-fix-composite-literal-checks

Conversation

Copilot AI commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

seenmapbool decided whether a map[string]bool was a pure true-sentinel set by scanning only for later m[k] = v statements, never inspecting the composite literal supplied at the declaration. A map populated in one shot with mixed values was therefore misflagged, suggesting a map[string]struct{} conversion that would drop real false entries.

func BadCompositeLiteralMixedValues() {
	flags := map[string]bool{"enabled": true, "disabled": false} // previously flagged as "used as a set"
	_ = flags
}

Changes

  • findNonSetMaps now also visits initializers, not just IndexExpr assignments:
    • *ast.ValueSpec values, covering the var flags = map[string]bool{...} branch.
    • *ast.AssignStmt RHS when the LHS is a plain identifier, covering the := branch.
  • New markIfNonSetLiteral helper — for a candidate whose initializer is an *ast.CompositeLit, marks it non-set if any KeyValueExpr.Value fails isBoolTrue, mirroring how a later m[k] = false is handled.
  • Initializers that are not composite literals (make(...), calls, map copies) return early, so existing candidate collection and diagnostics are untouched.

Tests

Added two testdata cases expecting no diagnostic: GoodBoolMapLiteralWithFalse (:= form) and GoodBoolMapVarLiteralWithFalse (var form). Existing BadSetBool*, GoodBoolMapWithFalse, closure, and //nolint cases are unchanged.

…es as non-set maps

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix seenmapbool false positive for composite literals fix(seenmapbool): treat non-true values in declaration-site composite literals as non-set maps Aug 9, 2026
Copilot AI requested a review from pelikhan August 9, 2026 04:45
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Great work on this fix! 🎯 This PR correctly addresses the issue where the seenmapbool linter was misflagging map[string]bool composite literals with mixed boolean values. The changes are focused, well-tested with both := and var forms covered, and the description clearly explains the bug and solution. The implementation properly mirrors existing false-detection logic at the initialization site, and test coverage ensures both good and bad cases are caught. Ready for review!

Generated by ✅ Contribution Check · auto · 80.4 AIC · ⌖ 4.92 AIC · ⊞ 8.8K ·

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: low
  • Priority: low
  • Score: 31/100 (impact 15 + urgency 8 + quality 8)
  • Recommended action: defer

Small draft lint-tool fix, low urgency, still in progress.

Generated by 🔧 PR Triage Agent · auto · 58.3 AIC · ⌖ 2.48 AIC · ⊞ 8K ·

@pelikhan
pelikhan marked this pull request as ready for review August 9, 2026 11:08
Copilot AI balanced review requested due to automatic review settings August 9, 2026 11:08
@pelikhan
pelikhan merged commit d15af45 into main Aug 9, 2026
@pelikhan
pelikhan deleted the copilot/seenmapbool-fix-composite-literal-checks branch August 9, 2026 11:08

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 seenmapbool false positives for maps initialized with meaningful false values.

Changes:

  • Inspects var and assignment initializers.
  • Marks mixed-value composite literals as non-set maps.
  • Adds regression cases for := and var declarations.
Show a summary per file
File Description
pkg/linters/seenmapbool/seenmapbool.go Adds declaration-site literal analysis.
pkg/linters/seenmapbool/testdata/src/seenmapbool/seenmapbool.go Adds mixed-value literal test cases.

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: 2
  • Review effort level: Balanced

Comment on lines +207 to +210
lit, ok := value.(*ast.CompositeLit)
if !ok {
return
}
Comment on lines +152 to +153
if i < len(valSpec.Values) {
markIfNonSetLiteral(pass, name, valSpec.Values[i], candidates, nonSetMaps)
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

seenmapbool: composite-literal initial values are never checked, so a map with a real false entry is misflagged as a pure set

3 participants