A function takes a context.Context after other parameters

tx0/go:context-not-firststrictwarningstyle

What it finds

func Fetch(url string, ctx context.Context): Go code passes the context first, as the context package documents and the standard library does throughout, so readers and tools look for it there.

The function or method must have a parameter of type context.Context, resolved through the imports of the file, that is not its first. Test helpers that take a *testing.T, *testing.B or testing.TB first are left alone, since those come first by their own convention.

From the rule's source, context_not_first.rs.

Example from the rule's tests
package p import (	"context"	"testing") func fetch(url string, ctx context.Context) error { return nil }tx0 reports: the context is not the first parameter func get(ctx context.Context, url string) error { return nil } func helper(t *testing.T, ctx context.Context) {}
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:context-not-first" = "warning"

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:context-not-first] reason="..."

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