Is there way to force code style to have trailing ...
# intellij
e
Is there way to force code style to have trailing comma but with one exception for when cases
Copy code
return when (view) {
                    is ContractView,
                    is ProductTile,
                    -> view.tag == text

                    else -> false
                }
Looks a bit odd.
youtrack 2
e
You could write a custom Ktlint rule. I’m currently working on a package of rule flavors that adjusts a few things from the Ktlint official style. Feel free to check it out for examples (you’ll have to dig around in the code a bit)https://github.com/Kantis/kantis-ktlint-rules
e
Thanks!
e
I think it's invalid to call it useless in 2nd case?
Copy code
fun foo(bar: Any)  {
    val a = when (bar) {
        is Int,  //"Useless trailing comma" not reported
        -> true
        else -> false
    }
}
Can be modified to
Copy code
fun foo(bar: Any)  {
    val a = when (bar) {
        is Int,  //"Useless trailing comma" not reported
        is Float,
        -> true
        else -> false
    }
}
Without having a diff on the line with "useless" comma.
a
I reckon in this case it can be reported as useless on the line with a Float check.
Or we need to add an option to the inspection settings...
@Emil Kantis What do you think?
I have looked again, and it looks as by-design behaviour in the second case as we lose an initial sense of trailing comma.
e
Anton, sorry coming back to my original question - is it correct behaviour? I believe in some extent it is. So I wonder if we could have a settings to override it.
e
I think it should be a separate rule all-together.. like "Single when-clause should be on a single line" to force
is X -> Y
to not contain linebreaks if it's just a single case
a
It is quite unclear indeed how we should proceed in this case. Maybe the best way will be adding an additional option to the inspection settings for this case (when condition + several options to check in a raw). It more looks like an unsupported yet case.