receiver-name-consistent
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...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) {}Configuration
Section titled “Configuration”go: lint: rules: receiver-name-consistent: warn # off (default), warn, errorEnabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line receiver-name-consistent in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | receiver-naming |
full |