skip to Main Content

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


  1. I tried to format your snippet in Android Studio Giraffe 2022.3.1 Canary 6 and it remains intact:
    enter image description here

    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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search