Skip to content

Add //nolint suppression parity to all CI-enforced custom linters#37237

Merged
pelikhan merged 2 commits into
mainfrom
copilot/sergo-fix-parity-gap-linters
Jun 6, 2026
Merged

Add //nolint suppression parity to all CI-enforced custom linters#37237
pelikhan merged 2 commits into
mainfrom
copilot/sergo-fix-parity-gap-linters

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

Nine CI-enforced custom analyzers were not honoring //nolint:<linter> directives, creating an enforcement gap versus linters already wired to internal/nolint. This change aligns suppression behavior across all enforced linters with shared same-line/previous-line directive semantics.

  • Suppression parity in enforced analyzers

    • Wired nolint.BuildLineIndex(pass, "<linter>") + nolint.HasDirective(...) into:
      • panicinlibrarycode
      • manualmutexunlock
      • osexitinlibrary
      • rawloginlib
      • regexpcompileinfunction
      • fprintlnsprintf
      • strconvparseignorederror
      • uncheckedtypeassertion
      • fmterrorfnoverbs
    • Diagnostic behavior is unchanged for unannotated code; only explicitly annotated sites are suppressed.
  • Regression coverage for directive handling

    • Added testdata fixtures for each updated linter covering both:
      • previous-line form: //nolint:<linter>
      • same-line form: ... //nolint:<linter>
    • Ensures parity remains stable as analyzers evolve.
  • Pattern applied

    idx := nolint.BuildLineIndex(pass, "fprintlnsprintf")
    pos := pass.Fset.PositionFor(call.Pos(), false)
    if nolint.HasDirective(pos, idx) {
        return
    }
    pass.Reportf(call.Pos(), "use fmt.Fprintf instead of fmt.Fprintln(w, fmt.Sprintf(...))")

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parity gap in CI-enforced custom linters handling of nolint directives Add //nolint suppression parity to all CI-enforced custom linters Jun 6, 2026
Copilot AI requested a review from gh-aw-bot June 6, 2026 02:39
@pelikhan pelikhan marked this pull request as ready for review June 6, 2026 03:30
Copilot AI review requested due to automatic review settings June 6, 2026 03:30
@pelikhan pelikhan merged commit 13df8e9 into main Jun 6, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/sergo-fix-parity-gap-linters branch June 6, 2026 03:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns all CI-enforced custom analyzers with the shared internal/nolint suppression behavior so //nolint:<linter> works consistently (same-line and previous-line) across the enforced linter set.

Changes:

  • Wired nolint.BuildLineIndex(pass, "<linter>") and nolint.HasDirective(...) into nine analyzers to honor //nolint:<linter> / //nolint:all.
  • Added/extended analysistest fixtures for each updated analyzer to cover both previous-line and same-line suppression forms.
  • Minor fixture formatting adjustments (e.g., gofmt/whitespace alignment) while adding the new suppression cases.
Show a summary per file
File Description
pkg/linters/uncheckedtypeassertion/uncheckedtypeassertion.go Adds internal/nolint directive suppression to unchecked type assertion diagnostics.
pkg/linters/uncheckedtypeassertion/testdata/src/uncheckedtypeassertion/uncheckedtypeassertion.go Adds suppression fixtures for previous-line and same-line directives.
pkg/linters/strconvparseignorederror/strconvparseignorederror.go Adds internal/nolint suppression for discarded-strconv error diagnostics.
pkg/linters/strconvparseignorederror/testdata/src/strconvparseignorederror/strconvparseignorederror.go Adds suppression fixtures and tightens formatting of existing want comments.
pkg/linters/regexpcompileinfunction/regexpcompileinfunction.go Adds internal/nolint suppression for regexp compilation-in-function diagnostics.
pkg/linters/regexpcompileinfunction/testdata/src/regexpcompileinfunction/regexpcompileinfunction.go Adds suppression fixtures for both directive placements.
pkg/linters/rawloginlib/rawloginlib.go Adds internal/nolint suppression for raw log.* calls in library packages.
pkg/linters/rawloginlib/testdata/src/rawloginlib/rawloginlib.go Adds suppression fixture cases for raw logging calls.
pkg/linters/panic-in-library-code/panic-in-library-code.go Adds internal/nolint suppression for panic() diagnostics in library packages.
pkg/linters/panic-in-library-code/testdata/src/panicinlibrarycode/panicinlibrarycode.go Adds suppression fixtures and applies gofmt-style formatting to the fixture.
pkg/linters/osexitinlibrary/osexitinlibrary.go Adds internal/nolint suppression for os.Exit diagnostics in library packages.
pkg/linters/osexitinlibrary/testdata/src/osexitinlibrary/osexitinlibrary.go Adds suppression fixtures for os.Exit.
pkg/linters/manualmutexunlock/manualmutexunlock.go Adds internal/nolint suppression for manual unlock (non-deferred) diagnostics.
pkg/linters/manualmutexunlock/testdata/src/manualmutexunlock/manualmutexunlock.go Adds suppression fixtures and normalizes whitespace.
pkg/linters/fprintlnsprintf/fprintlnsprintf.go Adds internal/nolint suppression for the Fprintln(Sprintf()) pattern.
pkg/linters/fprintlnsprintf/testdata/src/fprintlnsprintf/fprintlnsprintf.go Adds suppression fixtures for both directive placements.
pkg/linters/fmterrorfnoverbs/fmterrorfnoverbs.go Adds internal/nolint suppression for fmt.Errorf-without-verbs diagnostics.
pkg/linters/fmterrorfnoverbs/testdata/src/fmterrorfnoverbs/fmterrorfnoverbs.go Adds suppression fixtures for both directive placements.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 18/18 changed files
  • Comments generated: 1

Comment on lines +65 to +66
if nolint.HasDirective(pos, noLintLinesByFile) {
return
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.

[sergo] (nolint/redacted) parity gap: 9 of 11 CI-enforced custom linters silently ignore (nolint/redacted) directives

4 participants