Context TODO
ID |
go.context_todo |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Best Practice |
Language |
Go |
Tags |
best-practice, leftover-debug |
Description
Reports calls to context.TODO() left in the code. context.TODO is a placeholder the
standard library provides for code that has not yet decided which context to use.
Rationale
The documentation for context.TODO states it is meant to be used "when it’s unclear which
Context to use or it is not yet available" — it is a marker that the context plumbing is
unfinished. Functions that do work should accept a context.Context from their caller and
thread it through; only a true root (a main, a test, or a top-level request boundary) should
create one, and then it should use context.Background().
ctx := context.TODO() // FLAW — unfinished context plumbing
return context.Background() // OK — explicit root context