Add nolint parity to non-enforced context-family linters#41382
Merged
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add internal/nolint support for context-family linters
Add nolint parity to non-enforced context-family linters
Jun 25, 2026
Contributor
There was a problem hiding this comment.
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/nolintintoexeccommandwithoutcontext,ctxbackground,contextcancelnotdeferred, andtimesleepnocontextby 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
testdatafixtures to lock suppression behavior (plus updated.goldenoutputs 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four active context-propagation linters did not honor
//nolint:<analyzer>, unlikehttpnoctxand 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/nolintinto the remaining context-family lintersexeccommandwithoutcontextctxbackgroundcontextcancelnotdeferredtimesleepnocontextrunand consults it before reporting diagnostics.Apply suppression at the actual report sites
pass.Report/pass.ReportRangefpaths now skip diagnostics when the source line is covered by//nolint:<analyzer>or//nolint:all.contextcancelnotdeferredalso checks suppression when reporting deferred-cancel violations discovered through tracked state, including reassignment cases.Lock behavior with fixture coverage
//nolint:<analyzer>cases to each analyzer’stestdatapackage.Example suppression pattern now supported consistently across this linter family: