Skip to content

receiver-name-consistent

Gostyleno fixdefault: offgo/revive

The methods of a type declared in one file name their receiver the same. The first method sets the name; _, this and self are left to receiver-naming.

A method set reads as one unit. When one method calls its receiver s and the next srv, a reader has to check each body to know that both mean the same value, and a copied body keeps the wrong name. The Go code review comments ask for one receiver name per type.

Reported
...
type S[K any] struct{}
func (t T) A() {}
func (u *T) B() {}
func (t *T) C() {}
...
func (s *S[K]) H() {}
func (x *S[K]) I() {}
func (s S[K]) J() {}
type U struct{}
func (u U) A() {}
func (U) B() {}
func (v *U) C() {}
func f(t T) {}
go:
lint:
rules:
receiver-name-consistent: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line receiver-name-consistent 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