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

nuhkoca

09/27/2023, 9:49 PM
Why the latest ktlint formats when clauses like this? How do I fix this?
Copy code
SupportedType.Knockout,
SupportedType.Factor,
-> LeverageType.Long
p

Paul Dingemans

09/28/2023, 12:54 PM
When trailing comma’s are enabled the nthis is the way how it should be formatted. A trailing comma like below would not make sense:
Copy code
when {
    SupportedType.Knockout,
    SupportedType.Factor, -> LeverageType.Long
your alternative would be:
Copy code
when {
    SupportedType.Knockout, SupportedType.Factor -> LeverageType.Long
but as soon as the when condition contains a newline than the arrow will be wrapped to a separate line.
n

nuhkoca

09/30/2023, 8:35 AM
Thanks for the answer. Does this really make sense for my case? I mean trailing comma could’ve been disabled for
when
clause?
p

Paul Dingemans

09/30/2023, 10:06 AM
Depends on your settings. It is a valid place for a trailing comma.
2 Views