https://kotlinlang.org logo
#ktlint
Title
# ktlint
k

Kirill Zhukov

02/21/2024, 5:49 PM
Kotest uses following format for defining specs (tests):
Copy code
class MyTests : StringSpec({
   "length should return size of string" {
      "hello".length shouldBe 5
   }
})
Kotest (standard ruleset) formats it as following:
Copy code
class MyTests : StringSpec(
  {
    "length should return size of string" {
      "hello".length shouldBe 5
    }
  },
)
How do I prevent it from add a newline for the spec body lambda here? I see there was already this ticket for this from 4 years ago but curious if there's a solution here? What's the rule controlling this behavior?
e

Emil Kantis

02/21/2024, 7:39 PM
I think it's multiline-expression-wrapping that causes the issue. You can disable it by adding this to your
.editorconfig
Copy code
ktlint_standard_string-template-indent = disabled
ktlint_standard_multiline-expression-wrapping = disabled
k

Kirill Zhukov

02/21/2024, 10:15 PM
Already have both disabled
I think it's the trailing comma at the call site actually
ij_kotlin_allow_trailing_comma_on_call_site = false
disabling this fixes it
💯 1
e

Emil Kantis

02/21/2024, 10:17 PM
ah..
k

Kirill Zhukov

02/21/2024, 10:18 PM
Is there a way to make trailing commas at callsite optional? That is, they don't get added automatically but they don't get removed either.
It's nice to have in most cases, but I guess I wish it didn't remove the comms even if the rule is disabled
p

Paul Dingemans

02/22/2024, 5:24 PM
No this can not be configured. Either you choose to use them always, or never. Ktlint is more restrictive in this then default formatter of Intellij IDEA.
k

Kirill Zhukov

02/22/2024, 6:17 PM
Unfortunate! Thanks
4 Views