Boolean Property Naming
ID |
kotlin.boolean_property_naming |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Kotlin |
Tags |
naming, readability |
Description
Reports properties of type Boolean or Boolean? whose name does not start
with a predicate prefix (is, has, can, should, will, must, was,
are) and is not on the allow-list of standalone predicate names.
Rationale
Boolean values read best as predicates. A property named isRunning answers
the question "is it running?" at a glance, while running forces the reader
to look up the type before knowing what the value represents. The Kotlin
coding conventions explicitly recommend the predicate prefix convention.
// Bad — name does not read as a predicate
val running: Boolean = true // FLAW
// Good — predicate prefix
val isRunning: Boolean = true
// Good — common boolean names that already read as predicates
val enabled: Boolean = true
val visible: Boolean = false