suspicious assignment to a by-value method receiver
83
84func (opts ClientOptions) tokens() *tokens.Tokens {
85 if opts.Tokens == nil {
86 opts.Tokens = tokens.Parse(opts.AccessToken) 87 }
88
89 return opts.Tokens
Description
A method that modifies its receiver value can have undesired behavior. The modification can also be the root of a bug because the actual value receiver could be a copy of that used at the calling site. This rule warns when a method modifies its receiver.
Bad practice
type data struct {
num int
key *string
items map[string]bool
}
func (d data) vmethod() {
d.num = 8
}
Recommended
type data struct {
num int
key *string
items map[string]bool
}
func (d *data) vmethod() {
d.num = 8
}