You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new custom go/analysis linter nilctxpassed that detects function calls where nil is passed as a context.Context argument.
Why this matters
Passing nil as a context.Context is a common mistake that compiles successfully but panics at runtime the moment the callee calls ctx.Done(), ctx.Value(), ctx.Err(), or ctx.Deadline(). The correct idioms are context.Background() (for top-level callers with no parent context) or context.TODO() (for in-progress refactors).
This pattern is easy to introduce accidentally — e.g., during refactoring, a developer removes a context parameter and replaces the argument with nil — and the error is silently accepted by the compiler because nil is assignable to any interface type.
What the linter does
For every call expression, nilctxpassed:
Resolves the callee's *types.Signature via TypesInfo.
For each argument position that accepts context.Context, checks whether the supplied argument is the untyped nil identifier.
Reports a diagnostic: nil passed as context.Context; use context.Background() or context.TODO() instead.
pkg/linters/nilctxpassed/nilctxpassed_test.go — analysistest-based test
pkg/linters/nilctxpassed/testdata/src/nilctxpassed/nilctxpassed.go — fixture with want annotations
cmd/linters/main.go — registration in the multichecker binary
pkg/linters/README.md — documentation update
Testing
go test ./pkg/linters/nilctxpassed/...
ok github.com/github/gh-aw/pkg/linters/nilctxpassed
Build of cmd/linters succeeds.
Warning
Protected Files — Push Permission Denied
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.md
The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.
Create the pull request manually
# Download the patch from the workflow run
gh run download 29437953388 -n agent -D /tmp/agent-29437953388
# Create a new branch
git checkout -b linter-miner/nilctxpassed-43e2c076b291d576 main
# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-29437953388/aw-linter-miner-nilctxpassed.patch
# Push the branch and create the pull request
git push origin linter-miner/nilctxpassed-43e2c076b291d576
gh pr create --title '[linter-miner] feat(linters): add nilctxpassed linter' --base main --head linter-miner/nilctxpassed-43e2c076b291d576 --repo github/gh-aw
Summary
Adds a new custom
go/analysislinternilctxpassedthat detects function calls wherenilis passed as acontext.Contextargument.Why this matters
Passing
nilas acontext.Contextis a common mistake that compiles successfully but panics at runtime the moment the callee callsctx.Done(),ctx.Value(),ctx.Err(), orctx.Deadline(). The correct idioms arecontext.Background()(for top-level callers with no parent context) orcontext.TODO()(for in-progress refactors).This pattern is easy to introduce accidentally — e.g., during refactoring, a developer removes a context parameter and replaces the argument with
nil— and the error is silently accepted by the compiler becausenilis assignable to any interface type.What the linter does
For every call expression,
nilctxpassed:*types.SignatureviaTypesInfo.context.Context, checks whether the supplied argument is the untypednilidentifier.nil passed as context.Context; use context.Background() or context.TODO() instead.Files changed
pkg/linters/nilctxpassed/nilctxpassed.go— analyzer implementationpkg/linters/nilctxpassed/nilctxpassed_test.go—analysistest-based testpkg/linters/nilctxpassed/testdata/src/nilctxpassed/nilctxpassed.go— fixture withwantannotationscmd/linters/main.go— registration in the multichecker binarypkg/linters/README.md— documentation updateTesting
Build of
cmd/linterssucceeds.Warning
Protected Files — Push Permission Denied
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.mdThe push was rejected because GitHub Actions does not have
workflowspermission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.Create the pull request manually