When formatting this code block (from the Kotest documentation), Jetbrains Intellij or Android Studio adds a lot of unnecessary white space.
Original code:
class MyTests : FreeSpec({
"String.length" - {
"should return the length of the string" {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
})
After formating with ctrl+alt+L, this becomes
class MyTests : FreeSpec({
"String.length" - {
"should return the length of the string" {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
})
Is there a formatting setting to adjust this behavior?
I strongly suspect that there is a working combination of settings in Editor -> Code Style -> Kotlin, but after trying out various combinations I could not figure it out.
2
Answers
I tried to format your snippet in
Android Studio Giraffe 2022.3.1 Canary 6
and it remains intact:I suggest you to try a fresh installation of Android Studio/IntelliJ together with a fresh app using Kotest and see if the issue resurfaces.
If it doesn’t then you can compare the following files of the two projects to figure out the difference:
$projectRootDir/.idea/codeStyles/Project.xml
You may duplicate a formating scheme to alter safely or just do the following things.
Editor > Code Style > Kotlin > Wrapping and Braces > Function call arguments
Uncheck
Align when multiline
I also use Kotest FreeSpec. This was the tweak I made to have nice formatting.