Skip to content

Linter (nolint/redacted) parity: add nolint.BuildLineIndex support to enforce-candidate linters (seenmapbool, tolowerequalfold) #37251

Closed

Description

@github-actions

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+ local map[string]bool set sites, and its inspectBody is escape-blind (flags maps that are returned/passed/stored). Those false positives cannot all be converted to map[string]struct{} without cross-function changes, so a //nolint:seenmapbool escape 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:

  1. In run(pass), build the index once: idx := nolint.BuildLineIndex(pass, "<linterName>")
  2. Before each pass.ReportRangef(...), guard with if nolint.HasDirective(pass.Fset.Position(node.Pos()), idx) { return }
  3. Add testdata cases exercising a suppressed line

Validation checklist

  • seenmapbool imports internal/nolint, builds the index, and suppresses flagged lines carrying //nolint:seenmapbool
  • tolowerequalfold same
  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

cookiesergo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions