Experimental rules
Important
Up and until Ktlint version 0.47, experimental were located in a separate experimental rule set. As of Ktlint version 0.48, each rule set can optionally define experimental rules.
All experimental rules described below are part of the standard rule set of Ktlint. To enable all experimental rules (from all rule sets), set editorconfig property below:
Blank line before file annotation¶
Requires a blank line before the file annotation unless that file annotation is on the first line of the file.
Rule id: standard:blank-line-before-file-annotation
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
Note
This rule is only run when ktlint_code_style is set to ktlint_official or android_studion or when the rule is enabled explicitly.
Blank line before imports¶
Requires a blank line before the imports unless the imports starts at the first line of the file.
Rule id: standard:blank-line-before-imports
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
Note
This rule is only run when ktlint_code_style is set to ktlint_official or android_studion or when the rule is enabled explicitly.
Blank line before package¶
Requires a blank line before the package statement unless the package statement is the first line of the file.
Rule id: standard:blank-line-before-package
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
Note
This rule is only run when ktlint_code_style is set to ktlint_official or android_studion or when the rule is enabled explicitly.
Call expression wrapping¶
In case a call expression does not fit on the line, the lambda expression, and/or the value argument list after a reference expression are wrapped.
Rule id: standard:call-expression-wrapping
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
Expression operand wrapping¶
Wraps each operand in a multiline expression to a separate line.
Rule id: standard:expression-operand-wrapping
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
Lambda return¶
Do not use a labeled return for the last statement in a lambda if that label refers to the lambda itself.
val foo =
"Foo"
.let outer@{ foo ->
if (foo != "Foo") {
return@outer "$foo is not expected input"
}
foo
.let { "$it was a" }
.let secondLet@{
if (foo != "Foo") {
return@secondLet "$foo is not expected input"
}
"$it success"
}.let { return@outer "$it (map after let)" }
// This is unreachable code due to "return@outer" in let above.
"$foo was a failure"
}.let { "$it (let after also)" }
val foo =
"Foo"
.let outer@{ foo ->
if (foo != "Foo") {
return@outer "$foo is not expected input"
}
foo
.let { return@let "$it was a" }
.let secondLet@{
if (foo != "Foo") {
return@secondLet "$foo is not expected input"
}
return@secondLet "$it success"
}.let { return@outer "$it (map after let)" }
// This is unreachable code due to "return@outer" in let above.
return@outer "$foo was a failure"
}.let { return@let "$it (let after also)" }
Rule id: standard:lambda-return
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig
No blank line at start of file¶
Don't allow whitespace at the start of the file.
Rule id: standard:no-blank-line-at-start-of-file
Suppress or disable rule (1)
- Suppress rule in code with annotation below:
Enable rule via
.editorconfigDisable rule via.editorconfig