Closed andre-krueger closed 2 years ago
I tried running this release, which resulted in this:
.../MainActivity.kt:14:38: Unnecessary trailing comma before ")" (trailing-comma)
.../MainActivity.kt:17:9: Missing { ... } (multiline-if-else)
.../MainActivity.kt:18:24: Unnecessary trailing comma before ")" (trailing-comma)
.../MainActivity.kt:20:9: Missing { ... } (multiline-if-else)
.../MainActivity.kt:29:37: Unnecessary trailing comma before ")" (trailing-comma)
.../MainActivity.kt:33:37: Unnecessary trailing comma before ")" (trailing-comma)
After adding braces to the branches it works, though:
val test: List<Int> = emptyList()
) {
fun toUiState() = if (test.isNotEmpty()) {
TestUiState.TestA(
test = test
)
} else {
TestUiState.TestB(
test = test
)
}
}
The previous ktlint (0.45.2) worked fine, btw.
When running ktlint --format
, the braces are added automatically, although not correctly formatted.
Output after first format run (notice the missing space after the curly brace before else
):
private data class TestState(
val test: List<Int> = emptyList()
) {
fun toUiState() = if (test.isNotEmpty()) {
TestUiState.TestA(
test = test
)
}else {
TestUiState.TestB(
test = test
)
}
}
So I guess Spotless can't autocorrect
According to the Spotless team, it seems to be that ktlint is not propagating the fix.multiline-if-else
?
.../MainActivity.kt:14:38: Unnecessary trailing comma before ")" (trailing-comma) .../MainActivity.kt:17:9: Missing { ... } (multiline-if-else) .../MainActivity.kt:18:24: Unnecessary trailing comma before ")" (trailing-comma) .../MainActivity.kt:20:9: Missing { ... } (multiline-if-else) .../MainActivity.kt:29:37: Unnecessary trailing comma before ")" (trailing-comma) .../MainActivity.kt:33:37: Unnecessary trailing comma before ")" (trailing-comma)
Rules above have been promoted from experimentatl to standard in 0.46. See changelog
Expected Behavior
Code should format without error.
Observed Behavior
When trying to format the code (can also be seen in the attached reproduction), this occurs:
Steps to Reproduce
Reproduction.zip Download the reproduction and format the code via
./gradlew spotlessApply
Your Environment
.editorconfig
settings