Skip to content

feat(linters): add stringscountcontains linter#44820

Draft
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/linter-minerstringscountcontains-a96c73762fdd
Draft

feat(linters): add stringscountcontains linter#44820
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/linter-minerstringscountcontains-a96c73762fdd

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Adds a new stringscountcontains custom Go analysis linter that flags strings.Count(s, sub) comparisons with 0 or 1 used purely as containment checks. strings.Count walks the entire string while strings.Contains short-circuits on first match — making the latter both clearer in intent and more efficient.

Flagged patterns → suggested fix

// flagged → strings.Contains(s, sub)
strings.Count(s, sub) > 0
strings.Count(s, sub) >= 1
strings.Count(s, sub) != 0
0 < strings.Count(s, sub)   // yoda variants

// flagged → !strings.Contains(s, sub)
strings.Count(s, sub) == 0
strings.Count(s, sub) < 1
strings.Count(s, sub) <= 0
0 == strings.Count(s, sub)  // yoda variants

// not flagged — actual count usage
strings.Count(s, sub) > 2

Changes

  • pkg/linters/stringscountcontains/ — new analyzer package; emits SuggestedFix text edits for automated batch repair; respects //nolint:stringscountcontains directives; skips _test.go files
  • stringscountcontains_test.go — uses analysistest.RunWithSuggestedFixes with a .go.golden file, consistent with other fix-emitting linters
  • cmd/linters/main.go — registered in the multichecker binary
  • pkg/linters/README.md — documented in overview list, subpackages table, and import paths section
  • pkg/linters/spec_test.go — added to documentedAnalyzers() (39 → 40 documented analyzers)

Copilot AI and others added 2 commits July 10, 2026 19:28
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… comment

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add stringscountcontains linter feat(linters): add stringscountcontains linter Jul 10, 2026
Copilot AI requested a review from pelikhan July 10, 2026 19:30
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Category: feature | Risk: low | Priority: low | Score: 30/100 (impact:15, urgency:5, quality:10) | Action: batch_review | Batch: pr-batch:draft-review

Adds stringscountcontains linter flagging inefficient strings.Count comparisons. Additive/low-risk. Still a draft; no CI yet. Grouped with other draft PRs for batch review.

Generated by 🔧 PR Triage Agent · 31.2 AIC · ⌖ 8.39 AIC · ⊞ 5.4K ·

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] feat(linters): add stringscountcontains linter

2 participants