Skip to content

[linter-miner] feat(linters): add nilctxpassed linter #45795

Description

@github-actions

Summary

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:

  1. Resolves the callee's *types.Signature via TypesInfo.
  2. For each argument position that accepts context.Context, checks whether the supplied argument is the untyped nil identifier.
  3. Reports a diagnostic: nil passed as context.Context; use context.Background() or context.TODO() instead.

Files changed

  • pkg/linters/nilctxpassed/nilctxpassed.go — analyzer implementation
  • pkg/linters/nilctxpassed/nilctxpassed_test.goanalysistest-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

Generated by Linter Miner · 91.8 AIC · ⌖ 9.51 AIC · ⊞ 5.5K ·

  • expires on Jul 22, 2026, 10:01 AM UTC-08:00

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions