Repository navigation
Description
Summary
9 custom analyzers emit analysis.SuggestedFix text edits (batch-applied under -fix), but only 6 verify the emitted fix output via analysistest.RunWithSuggestedFixes + a .golden file. 3 emit fixes whose generated source is never checked by any test:
| Linter | Emits SuggestedFix | Fix builder | Test entrypoint | .golden? |
|---|---|---|---|---|
stringsindexcontains (new, R56 registry 40→41) |
yes | buildContainsFix (stringsindexcontains.go:226-242) |
analysistest.Run (stringsindexcontains_test.go:15) |
none |
sprintfint |
yes | buildItoaFix (sprintfint.go:94-107) |
analysistest.Run (sprintfint_test.go:16) |
none |
stringreplaceminusone |
yes | buildReplaceAllFix (stringreplaceminusone.go:96-116) |
analysistest.Run (stringreplaceminusone_test.go:15) |
none |
The 6 that DO verify: ctxbackground, execcommandwithoutcontext, fprintlnsprintf, lenstringsplit, lenstringzero, tolowerequalfold (8 .golden files total under pkg/linters/).
Why this matters
analysistest.Run only checks diagnostic positions/messages (the // want comments). It never applies the TextEdits, so the reconstructed replacement string is completely unexercised. For an autofix linter that is -fix-applied in batch, a defect in the fix builder ships silently — the diagnostic still lands on the right line, but the rewritten code is wrong.
This is not hypothetical: R55 found a real semantic-change bug in a fix builder (fprintlnsprintf buildFprintfFix dropped a trailing newline). That linter did have golden coverage, which is how such regressions are meant to be caught. The 3 linters above have no such safety net, so any future edit to their fix builders (or a latent defect today) would not be detected.
Concrete latent-risk examples in the uncovered set:
sprintfintdocuments in its ownAnalyzer.Docthat fixes "may require goimports to add/remove imports" — thestrconv.Itoa(...)rewrite (sprintfint.go:105) leavesstrconvunimported /fmtpossibly unused. Import-management behavior is precisely the kind of thing a golden file pins.stringsindexcontainsreconstructs the replacement fromastutil.NodeText(go/printer reprint of the arg AST,astutil.go:117), e.g."!" + pkg + ".Contains(" + sText + ", " + subText + ")"(stringsindexcontains.go:229). The reprinted-arg + negation path is untested.
(Note: I audited stringsindexcontains's detection and fix logic and both are semantically correct today — all 6 comparison forms + yoda variants map correctly to strings.Contains/!strings.Contains, args preserved in call order. This issue is about the missing verification harness, not a known miscompile.)
Evidence
Grep reconciliation
# emit SuggestedFix (non-test):
pkg/linters/{ctxbackground,execcommandwithoutcontext,fprintlnsprintf,lenstringsplit,
lenstringzero,sprintfint,stringreplaceminusone,stringsindexcontains,
tolowerequalfold}/*.go → 9 linters
# use RunWithSuggestedFixes (test):
pkg/linters/{ctxbackground,execcommandwithoutcontext,fprintlnsprintf,lenstringsplit,
lenstringzero,tolowerequalfold}/*_test.go → 6 linters
# *.golden under pkg/linters/ → 8 files (all belong to the 6 verified linters)
# stringsindexcontains / sprintfint / stringreplaceminusone → 0 golden, analysistest.Run only
Recommended fix (uniform, per linter)
For each of the 3 linters:
- Add a
testdata/src/<name>/<name>.go.goldencapturing the expected post-fix source for each// wantcase (contains + negated + yoda variants; forsprintfint, thestrconv.Itoarewrite). - Switch the test from
analysistest.Run(...)toanalysistest.RunWithSuggestedFixes(t, testdata, <pkg>.Analyzer, "<name>")— matching the pattern already used byfprintlnsprintf_test.go,lenstringzero_test.go, etc.
Validation checklist
-
go test ./pkg/linters/stringsindexcontains/... ./pkg/linters/sprintfint/... ./pkg/linters/stringreplaceminusone/...passes withRunWithSuggestedFixes. - Each
.goldenreflects the exact reprinted replacement (verifysprintfintgolden documents the import-management caveat, or gate the linter out of-fixbatches until goimports is wired). - All 9 SuggestedFix linters now covered → grep parity:
RunWithSuggestedFixescount == SuggestedFix-emitting count.
Effort: small–medium (test-only; 3 golden files + 3 one-line test swaps). No production analyzer changes required.
References: run §28695406176
Generated by 🤖 Sergo - Serena Go Expert · 387.7 AIC · ⌖ 14 AIC · ⊞ 5.9K · ◷
- expires on Jul 10, 2026, 9:07 PM UTC-08:00
Activity
github-actions commentedon Jul 4, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪