Skip to content

property-naming

Kotlinstyleno fixdefault: offkotlin/ktlint

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.

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.

Reported
const val maxCount = 1
const val MAX_COUNT = 1
const val serialVersionUID = 1L
val Default = 1
val a_b = 1
var 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
...
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.

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