nil is passed as the parent context to a function of context, which panics

tx0/go:nil-contextdefaultwarningbug

What it finds

context.WithTimeout(nil, d): the functions of context that derive a new context panic when the parent is nil. A function without a context of its own to pass starts from context.Background() or, while the right one is not yet known, context.TODO().

The first argument must be the literal nil and the function one of context, resolved through the imports of the file.

From the rule's source, nil_context.rs.

Example from the rule's tests
package p import (	"context"	"time") func f() {	ctx, cancel := context.WithTimeout(nil, time.Second)tx0 reports: context.WithTimeout panics with a nil parent	defer cancel()	_ = context.WithValue(nil, key{}, 1)tx0 reports: context.WithValue panics with a nil parent	ctx, cancel = context.WithCancel(ctx)	defer cancel()} type key struct{}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/go:nil-context" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:nil-context] reason="..."

tx0 explain tx0/go:nil-context shows the same in the terminal. Found a false positive? Report it.