Boolean Getter Naming
ID |
go.boolean_get_function_name |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Go |
Tags |
naming |
Description
Reports a function or method that returns a single bool but whose name starts with Get
or get. A boolean predicate reads better with an Is or Has prefix.
Rationale
Get advertises an accessor that yields a value; for a boolean the idiomatic prefix is Is
or Has, which reads naturally at the call site (if user.IsActive()). Tuple results such as
(bool, error) are lookups rather than simple predicates and are left alone.
// Bad — Get prefix on a boolean
func GetActive() bool { return true } // FLAW
// Good — Is/Has prefix
func IsActive() bool { return true } // OK
func HasChildren() bool { return false } // OK
func GetName() string { return "" } // OK — not a bool