what is the best kotlin formatter , My team finds ...
# getting-started
s
what is the best kotlin formatter , My team finds it difficult with formatting style of intellij Ktlintformat… Any other formatter or ways to improve ktlintformat ?
p
What is the problem with ktlint? It enforces the official Kotlin coding conventions.
j
I'm here to ask the same question. The only problem i found out with ktlint (but truly it's a problem with intellij i believe) is that sometimes there are differences between intellij auto formatting and what ktlint does. But it's truly minor
p
You can import the Ktlint Format to IntelliJ but as you already mentioned, there are some problems: https://pinterest.github.io/ktlint/rules/configuration-intellij-idea/
j
yup, but it's really minor. We have a process on CI that formats the code and commits back to pull request
so we truly don't care 😄
o
ktfmt
https://github.com/facebook/ktfmt An opinionated formatter without any customization options (conscious choice). Just look at the comparison screenshots to see how bad everything else is in comparison. Then again, relinquishing all control over source code formatting may not suit everyone. I find it to be excellent. Not only is it superior in terms of the actual formatting algorithm, but its lack of customizability leaves no room for bikeshedding and personal opinions.
a
personally I prefer committing a
.editorconfig
file, or the IntelliJ code style xml, and asking everyone to check the “format code on commit”. It’s more lightweight, and doesn’t get in the way or nag when I’m in the middle of something.
plus one 1
k
Regarding the screenshots shown in ktfmt's Github site, IntelliJ puts the closing parenthesis of a function call on a new line, which conforms to the standard Kotlin Coding Conventions. This means the screenshot they have of IntelliJ not doing that is not accurate. And also ktfmt puts the closing parenthesis on the same line as the last parameter, so it doesn't conform to the convention.
s
i add a few empty lines while coding and ktfmt will not remove them, Do i miss anything to format and remove such empty lines ?