Skip to content

receiver-naming

Gostyleno fixdefault: offgo/revive

The name of a method’s receiver is _, this or self: a receiver is named by a short form of its type, and left out when the method does not use it.

this and self carry the habits of other languages into Go, where a receiver is an ordinary parameter named after its type (s for Server). A _ receiver is the same as no name, so leaving the name out says the method does not use the value. The Go code review comments ask for short names taken from the type.

Reported
...
func (t T) A() {}
...
func (t *T) C() {}
func (self T) D() {}
func (_ T) E() {}
func (T) F() {}
func (this *T) G() {}
func (s *S[K]) H() {}
...
go:
lint:
rules:
receiver-naming:
level: warn # off (default), warn, error
options:
receivers: "!^(?:_|this|self)$"
Option Type Default Description
receivers string `“!^(?:_ this

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line receiver-naming in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
revive receiver-naming full