Skip to content

context-key-type

Detect unsafe context.WithValue key types.

Updated View as Markdown

Default severity: warning

Context keys must be comparable and should use a dedicated named type to avoid collisions between packages. Built-in types and anonymous empty structs risk collisions; non-comparable and nil keys panic at runtime.

This type-aware check supersedes the earlier syntax-only implementation.

Bad

ctx = context.WithValue(ctx, "request-id", value)

Good

type contextKey struct{}
ctx = context.WithValue(ctx, contextKey{}, value)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close