Reputation: 10030
I currently use the following way to apply ktlint to my projects:
plugins{
id("com.diffplug.spotless") version "6.7.2"
}
allprojects {
apply(plugin = "com.diffplug.gradle.spotless")
spotless {
kotlin {
target("**/*.kt")
ktlint("0.45.2")
}
kotlinGradle {
target("*.gradle.kts", "additionalScripts/*.gradle.kts")
ktlint("0.45.2")
}
}
}
I want to tweak some on the configurations so that the linter fits with what we want in the team. for example, set a max line length to 120.
For this, I found that we can do something like:
ktlint("0.30.0").userData(mapOf("max_line_length" to "120"))
in the build.gradle.kts file. However, as we go on adding more tweaks, this becomes very difficult to manage and copy from project to project, and the spotlessApply
task fails to format the code and simply raises it as an issue during the build.Is it possible to get it to auto-format in this case?
ktlint itself supports the .editorconfig
file for such configurations. How do I apply that with spotless?
Upvotes: 5
Views: 6120
Reputation: 15669
Three years later - but better late than never! - it works.
Starting in Spotless version 6.13.0
and ktlint versions 0.47.1
and 0.48.1
this behavior now works out of the box.
Upvotes: 1