ktlint icon indicating copy to clipboard operation
ktlint copied to clipboard

Multiline lambda in function call or condition formated different than IntelliJ formatter

Open miikeat opened this issue 3 years ago • 2 comments

Expected Behavior

IntelliJ with official Kotlin code style formats the following code like this:

val list = listOf<Boolean>()
fun test() {
    if (list.all {
            it == true
        }
    ) {
    }
}

Observed Behavior

ktlint complains about wrong indentation:

test.kt:4:1 Unexpected indentation (12) (should be 8) (indent)
test.kt:5:1 Unexpected indentation (8) (should be 4) (indent)

ktlintFormat changes the code to:

val list = listOf<Boolean>()
fun test() {
    if (list.all {
        it == true
    }
    ) {
    }
}

Your Environment

  • Version of ktlint used: 0.41.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): KtLint Gradle 10.0.0
  • Version of Gradle used (if applicable): 7.1.1
  • Operating System and version: OS: Garuda Linux - 5.10.55-1-lts

miikeat avatar Aug 06 '21 11:08 miikeat

@miikeat would you be able to try with the latest snapshot and see if you're still getting this issue?

shashachu avatar Aug 06 '21 15:08 shashachu

This problem still occurs with latest snapshot.

paul-dingemans avatar Aug 07 '21 17:08 paul-dingemans

Solved by #1682

paul-dingemans avatar Oct 24 '22 18:10 paul-dingemans

Closed by #1682

paul-dingemans avatar Oct 26 '22 17:10 paul-dingemans