A getter method is named with the prefix Get
What it finds
func (u *User) GetName() string: Go names a getter after what it returns, as u.Name(), and keeps the Set prefix for setters. The Get prefix only lengthens every call.
Reported are exported methods named Get followed by an upper-case letter that take no parameters and return one result. Code generated from protocol buffers, which uses the prefix, is skipped as generated code.
From the rule's source, getter_named_get.rs.
package p type User struct{ name string } func (u *User) GetName() string {tx0 reports: a getter is named after what it returns, as Name return u.name} func (u *User) GetOrCreate(id int) *User { return u} 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:
[rules]
"tx0/go:getter-named-get" = "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:getter-named-get] reason="..."tx0 explain tx0/go:getter-named-get shows the same in the terminal. Found a false positive? Report it.