Methods of one type name their receiver differently, or call it this or self

tx0/go:receiver-name-mismatchstrictwarningstyle

What it finds

func (s *Server) Start() next to func (srv *Server) Stop(): the receiver is the same value in every method, and one short name for it, used throughout, lets readers move between methods without translating. Names such as this and self carry habits of other languages, where the receiver is implicit.

Within one file, a method is reported when its receiver name differs from the one the first method of the same type uses, or when the name is this or self. Blank and missing receiver names are left alone.

From the rule's source, receiver_name_mismatch.rs.

Example from the rule's tests
package p type server struct{} func (s *server) start() {} func (srv *server) stop() {}tx0 reports: the receiver is named srv here but s in other methods of server func (s server) name() string { return "" } type client struct{} func (self *client) dial() {}tx0 reports: the receiver is named self
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:receiver-name-mismatch" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:receiver-name-mismatch] reason="..."

tx0 explain tx0/go:receiver-name-mismatch shows the same in the terminal. Found a false positive? Report it.