Repository navigation
Description
Overview
The custom linter framework has a strong, undocumented invariant: every linter currently enforced in CI supports the //nolint escape hatch, while several registered-but-unenforced linters do not. Two of those gaps (seenmapbool, tolowerequalfold) are active enforcement candidates, and for seenmapbool the missing escape hatch is a hard blocker to enforcement.
The invariant
12 of 21 registered linters integrate pkg/linters/internal/nolint (BuildLineIndex + HasDirective):
panicinlibrarycode, strconvparseignorederror, rawloginlib, fmterrorfnoverbs, manualmutexunlock, uncheckedtypeassertion, osexitinlibrary, fprintlnsprintf, regexpcompileinfunction, errstringmatch, jsonmarshalignoredeerror, errormessage
Crucially, all 11 CI-enforced linters are in that set (the 12th, errormessage, is opt-in). Historical evidence: fmterrorfnoverbs gained //nolint support at the same time it was enforced (R26). So //nolint support behaves as an enforcement precondition — it guarantees an escape hatch for the rare legitimate exception before the linter becomes blocking.
The 9 linters lacking (nolint/redacted) support
contextcancelnotdeferred ctxbackground excessivefuncparams
fileclosenotdeferred largefunc ossetenvlibrary
seenmapbool ssljson tolowerequalfold
Why this matters now (active candidates)
seenmapbool(pkg/linters/seenmapbool/seenmapbool.go) — 60+ localmap[string]boolset sites, and itsinspectBodyis escape-blind (flags maps that are returned/passed/stored). Those false positives cannot all be converted tomap[string]struct{}without cross-function changes, so a//nolint:seenmapboolescape hatch is a hard precondition for enforcing it. (Escape-filter precision work is tracked separately.)tolowerequalfold(pkg/linters/tolowerequalfold/tolowerequalfold.go) — now zero-FP and slated for enforcement via full site conversion; it can technically be enforced without//nolint, but adding the directive brings it in line with the convention and provides an escape hatch for any future edge case.
Recommendation
Add //nolint support to seenmapbool and tolowerequalfold (and consider the convention for the rest as they approach enforcement). The integration is the established ~3-5 line pattern used by 12 existing linters:
- In
run(pass), build the index once:idx := nolint.BuildLineIndex(pass, "<linterName>") - Before each
pass.ReportRangef(...), guard withif nolint.HasDirective(pass.Fset.Position(node.Pos()), idx) { return } - Add testdata cases exercising a suppressed line
Validation checklist
-
seenmapboolimportsinternal/nolint, builds the index, and suppresses flagged lines carrying//nolint:seenmapbool -
tolowerequalfoldsame - Each has a testdata case confirming suppression
- No behavior change for un-annotated code (existing testdata still passes)
Effort
Small per linter (~3-5 lines + a test), mirroring 12 existing integrations. Unblocks the seenmapbool enforcement path and standardizes the framework.
References: §27053183547
Generated by 🤖 Sergo - Serena Go Expert · 232.3 AIC · ⌖ 14.8 AIC · ◷
- expires on Jun 13, 2026, 5:09 AM UTC
Activity