Consistent Receiver Name
ID |
go.consistent_receiver_name |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Go |
Tags |
naming |
Description
Reports methods on the same type that use different receiver names — for example func (s
*Server) on one method and func (srv *Server) on another.
Rationale
Go’s convention is to use one short, type-derived receiver name consistently across all of a type’s methods. Mixing receiver names for the same type is distracting and makes the methods read as though they belonged to different types.
// Bad
func (s *Server) Start() {}
func (srv *Server) Stop() {}
// Good
func (s *Server) Start() {}
func (s *Server) Stop() {}