ktlint
ktlint copied to clipboard
Indent code in string template conflicts with default IntelliJ IDEA formatting
Expected Behavior
Code below is formatted with IntelliJ IDEA default formatting and should be accepted by KtLint without changes:
fun foo1() =
"Sum of uneven numbers = ${
listOf(1, 2, 3)
.filter { it % 2 == 0 }
.sum()
}"
fun foo2() = "Sum of uneven numbers = ${
listOf(1, 2, 3)
.filter { it % 2 == 0 }
.sum()
}"
Observed Behavior
Klint 0.46.1 reports following violations:
$ ktlint-0.46.1 --relative
src/main/kotlin/Foo.kt:3:1: Unexpected indentation (8) (should be 4) (indent)
src/main/kotlin/Foo.kt:4:1: Unexpected indentation (12) (should be 8) (indent)
src/main/kotlin/Foo.kt:5:1: Unexpected indentation (12) (should be 8) (indent)
src/main/kotlin/Foo.kt:9:1: Unexpected indentation (4) (should be 0) (indent)
src/main/kotlin/Foo.kt:10:1: Unexpected indentation (8) (should be 4) (indent)
src/main/kotlin/Foo.kt:11:1: Unexpected indentation (8) (should be 4) (indent)
which result in code:
fun foo1() =
"Sum of uneven numbers = ${
listOf(1, 2, 3)
.filter { it % 2 == 0 }
.sum()
}"
fun foo2() = "Sum of uneven numbers = ${
listOf(1, 2, 3)
.filter { it % 2 == 0 }
.sum()
}"
Your Environment
- Version of ktlint used: 0.46.1