receiver-naming
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...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() {}...Configuration
Section titled “Configuration”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.
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 |