Skip to content

function-naming

Kotlinstyleno fixdefault: offkotlin/ktlint

Reports a function whose name does not match the expression set for its kind: camel case; a function with a declared return type may also be a factory named in Pascal case. A function that is an override or @Composable is not reported.

Kotlin code reads functions in camel case, and a name in another case reads as a class or a constant. Factory functions that look like constructors (Foo()) and Compose functions are an exception by convention.

To fix, rename the function to camel case.

Reported
...
val ok = 1
val _backing = 1
...
fun My_fun() {}
fun Factory(): A = A()
fun my_fun2(): Int = 1
fun `a test name`() {}
override fun other_name() {}
}
...
kotlin:
lint:
rules:
function-naming:
level: warn # off (default), warn, error
options:
composables: ".*"
overridden: ".*"
factories: "^(?:[A-Za-z][A-Za-z0-9]*|`.*)$"
functions: "^(?:[a-z][A-Za-z0-9]*|`.*)$"
Option Type Default Description
composables string ".*" Regular expression the name of a @Composable function must match.
overridden string ".*" Regular expression the name of an override function must match.
factories string `“^(?:[A-Za-z][A-Za-z0-9]* .*)$"
functions string `“^(?:[a-z][A-Za-z0-9]* .*)$"

Enabled by the presets: kotlin/ktlint.

Suppress one line with sudsy-disable-next-line function-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 function-naming partial @Composable, override and backtick names are left alone; a factory function is a capitalised name with a declared return type