ktfmt is a program that pretty-prints (formats)
Kotlin code.
It always produces the same result, regardless of how the code looks initially, freeing developers to focus on essence.
It is by design non-customizable in order to promote consistency.
A ktfmt plugin that augments the Reformat Code action (⌥⌘L) is available from JetBrains Marketplace.
Spotless (details):
# build.gradle.kts
plugins { id("com.diffplug.spotless") }
// version and style are optional
spotless { kotlin { ktfmt('{{version}}').kotlinlangStyle() } }
or,
ktfmt-gradle (details):
# build.gradle.kts
plugins { id("com.ncorti.ktfmt.gradle") }
ktfmt { kotlinLangStyle() }
Spotless (details):
# pom.xml
<configuration>
<kotlin>
<ktfmt>
<version>{{version}}</version>
</ktfmt>
</kotlin>
</configuration>
Download the jar from Maven Central and invoke it using
java:
$ wget https://repo1.maven.org/maven2/com/facebook/ktfmt/{{version}}/ktfmt-{{version}}-jar-with-dependencies.jar
$ java -jar ktfmt-{{version}}-jar-with-dependencies.jar [--kotlinlang-style] [files...]