property-naming
What it does
Section titled “What it does”Reports a property whose name does not match the expression set for its kind: a const val is in UPPER_SNAKE_CASE; top-level and object properties may also be written as constants; a backing property may start with _; an override is not reported.
Why it matters
Section titled “Why it matters”The case of a name tells a reader if it is a constant or a variable. A const val in camel case reads as a variable that can change, and a mutable property in capitals reads as a constant.
To fix, rename the property to the style of its kind.
Example
Section titled “Example”const val maxCount = 1const val MAX_COUNT = 1const val serialVersionUID = 1Lval Default = 1val a_b = 1var Global = 1
class A { val MAX = 1 val ok = 1 val _backing = 1 val trailing_ = 1... fun Factory(): A = A()...}
fun local() { val LOCAL = 1}
@Composable...Configuration
Section titled “Configuration”kotlin: lint: rules: property-naming: level: warn # off (default), warn, error options: constants: "^(?:[A-Z][A-Z0-9_]*|serialVersionUID)$" overridden: ".*" singleton_members: "^(?:[a-z][A-Za-z0-9]*|[A-Z][A-Za-z0-9_]*|_[A-Za-z0-9_]*|`.*)$" top_level: "^(?:[a-z][A-Za-z0-9]*|[A-Z][A-Za-z0-9_]*|_[A-Za-z0-9_]*|`.*)$" members: "^(?:[a-z][A-Za-z0-9]*|_[A-Za-z0-9_]*|`.*)$"| Option | Type | Default | Description |
|---|---|---|---|
constants |
string | `“^(?:[A-Z][A-Z0-9_]* | serialVersionUID)$“` |
overridden |
string | ".*" |
Regular expression the name of an override property must match. |
singleton_members |
string | `“^(?:[a-z][A-Za-z0-9]* | [A-Z][A-Za-z0-9_]* |
top_level |
string | `“^(?:[a-z][A-Za-z0-9]* | [A-Z][A-Za-z0-9_]* |
members |
string | `“^(?:[a-z][A-Za-z0-9]* | [A-Za-z0-9]* |
Enabled by the presets: kotlin/ktlint.
Suppress one line with sudsy-disable-next-line property-naming in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| ktlint | property-naming |
partial | override properties are left alone; _name backing properties are not matched to a property |