Context First Argument

ID

go.context_first_argument

Severity

info

Remediation Complexity

simple

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Go

Tags

naming

Description

Reports a function or method that takes a context.Context parameter in a position other than the first.

Rationale

The pervasive Go convention is to pass the context as the leading parameter (func f(ctx context.Context, …​)), so cancellation and deadline propagation read uniformly across every API and tooling can recognise the pattern. A context buried among other parameters breaks that expectation.

// Bad
func f(id int, ctx context.Context) {} // FLAW

// Good
func f(ctx context.Context, id int) {} // OK
func f(id int) {}                       // OK — no context

Remediation

Move the context.Context parameter to the front of the parameter list.