Skip to content

Add nolint parity to non-enforced context-family linters#41382

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-nolint-parity-gap
Jun 25, 2026
Merged

Add nolint parity to non-enforced context-family linters#41382
pelikhan merged 2 commits into
mainfrom
copilot/fix-nolint-parity-gap

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Four active context-propagation linters did not honor //nolint:<analyzer>, unlike httpnoctx and the rest of the suppression-aware linter set. This left no inline escape hatch for legitimate false positives and created an inconsistency within the same linter family.

  • Wire internal/nolint into the remaining context-family linters

    • execcommandwithoutcontext
    • ctxbackground
    • contextcancelnotdeferred
    • timesleepnocontext
    • Each analyzer now builds a per-file nolint line index at the start of run and consults it before reporting diagnostics.
  • Apply suppression at the actual report sites

    • Direct pass.Report / pass.ReportRangef paths now skip diagnostics when the source line is covered by //nolint:<analyzer> or //nolint:all.
    • contextcancelnotdeferred also checks suppression when reporting deferred-cancel violations discovered through tracked state, including reassignment cases.
  • Lock behavior with fixture coverage

    • Added explicit //nolint:<analyzer> cases to each analyzer’s testdata package.
    • Existing positive cases remain unchanged; new fixtures verify that intentional exceptions are not reported.

Example suppression pattern now supported consistently across this linter family:

func runDetached(ctx context.Context, name string) {
	_ = exec.Command(name) //nolint:execcommandwithoutcontext
}
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add internal/nolint support for context-family linters Jun 25, 2026
Copilot AI requested a review from pelikhan June 25, 2026 05:48
@pelikhan pelikhan marked this pull request as ready for review June 25, 2026 05:56
Copilot AI review requested due to automatic review settings June 25, 2026 05:56
@pelikhan pelikhan merged commit 28242de into main Jun 25, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/fix-nolint-parity-gap branch June 25, 2026 05:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request brings //nolint:<analyzer> (and //nolint:all) suppression parity to the remaining “context-family” Go analyzers in pkg/linters, making inline false-positive escapes consistent with the rest of the suppression-aware linter set.

Changes:

  • Wired pkg/linters/internal/nolint into execcommandwithoutcontext, ctxbackground, contextcancelnotdeferred, and timesleepnocontext by building a per-file nolint line index at analyzer start.
  • Applied suppression checks at the diagnostic/report sites (including tracked-state reporting paths in contextcancelnotdeferred).
  • Added testdata fixtures to lock suppression behavior (plus updated .golden outputs where suggested fixes are used).
Show a summary per file
File Description
pkg/linters/timesleepnocontext/timesleepnocontext.go Builds nolint line index and skips reporting when the call site is covered by a nolint directive.
pkg/linters/timesleepnocontext/testdata/src/timesleepnocontext/timesleepnocontext.go Adds a suppression fixture to verify //nolint:timesleepnocontext prevents diagnostics.
pkg/linters/execcommandwithoutcontext/execcommandwithoutcontext.go Adds nolint indexing and suppression gating prior to emitting diagnostics/suggested fixes.
pkg/linters/execcommandwithoutcontext/testdata/src/execcommandwithoutcontext/execcommandwithoutcontext.go Adds a suppression fixture to ensure an intentional exec.Command is not reported when nolinted.
pkg/linters/execcommandwithoutcontext/testdata/src/execcommandwithoutcontext/execcommandwithoutcontext.go.golden Updates expected suggested-fix golden output to include the new “GoodNoLint” fixture.
pkg/linters/ctxbackground/ctxbackground.go Adds nolint indexing and suppression gating for context.Background() call diagnostics.
pkg/linters/ctxbackground/testdata/src/ctxbackground/ctxbackground.go Adds a suppression fixture to ensure nolinted context.Background() is not reported.
pkg/linters/ctxbackground/testdata/src/ctxbackground/ctxbackground.go.golden Updates expected suggested-fix golden output to include the new suppression fixture.
pkg/linters/contextcancelnotdeferred/contextcancelnotdeferred.go Threads nolint index through helper functions and suppresses deferred-cancel diagnostics based on the reported position line.
pkg/linters/contextcancelnotdeferred/testdata/src/contextcancelnotdeferred/contextcancelnotdeferred.go Adds a suppression fixture to ensure nolinted cancel creation lines are not reported.

Copilot's findings

Tip

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

  • Files reviewed: 10/10 changed files
  • Comments generated: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants