Does anyone run with the intelliJ formatter disabl...
# ktlint
r
Does anyone run with the intelliJ formatter disabled? I like to use ktlint as my only linter to avoid collisions on certain rules. But I'm running into this intelliJ bug where imports can be on the same line. Anyone have any work arounds?
p
What do you mean with
Does anyone run with the intelliJ formatter disabled?
Do you refer to ktlint-gradle plugin, or ktlint-intellij-plugin, ktlint CLI?
r
I am using the ktlint-intellij-plugin. Given my .editorconfig, there are small differences in how intelliJ and ktlint will format a file. I've opted to disable intelliJ file formatting for kotlin files (Editor -> Code Style -> Add *.kt to Do Not Format) to avoid these inconsistencies, purely letting ktlint do the formatting. But this causes the error linked above on certain intellij actions. I was wondering if anyone has run into a similar issue and has any work arounds.
p
Why would you disable Intellij formatting? Ktlint Intellij plugin runs after the Intellij formatting.
r
Yes, but formatting a file with intelliJ then ktlint is not always the same as just formatting with ktlint. For CI consistency (where we only run ktlint) we prefer to just use ktlint and not use intellIJ formatting.
p
If you use the default intellij settings this should not happen. Or, at least it never happened to me. I would be interested in a concrete example that reproduces this issue. If you have one, please create an issue in the ktlint issue tracker.
r
Seems to be tied to a specific rule:
Copy code
ij_kotlin_allow_trailing_comma_on_call_site = true
Example:
Copy code
class MinimalRepro : SuperClassWithLambda({
})

open class SuperClassWithLambda(lambda: () -> Unit)
Expected: No changes from intellij and no changes from ktlint. Actual: ktlint doesn't cause changes but intellij modifies this to
Copy code
class MinimalRepro : SuperClassWithLambda(
    {
    },
)

open class SuperClassWithLambda(lambda: () -> Unit)
I don't really care which one happens (mild preference for the no modification, but it is fine), but the difference in behavior causes some problems. If the goal of ktlint is to be no different from intellij formatter + ktlint that sounds good to me and I can leave intellij formatter enabled. I can also open a github issue if that is helpful.
I've played with this some more and I can simply disable the intelliJ rule. Ktlint will properly allow me to have trailing commas if I like while situations that don't need it will render fine.
p
With code style ktlint_official (default) there are some (intentional) discrepancies with Intellij format. You can try whether the other code styles are a better fit as they intend to be compatible with default formatter
119 Views