Kotlin 1.4 introduces the ability to have trailing commas (https://blog.jetbrains.com/kotlin/2019/12/what-to-expect-in-kotlin-1-4-and-beyond/#trailing-commas). ktlint currently marks this as invalid syntax
ktlint throws the following error:
Not a valid Kotlin file (expecting a parameter declaration) (cannot be auto-corrected)
Run ktlint on the following contents
data class Test(
val test1: String,
val test2: String,
) {
fun test(
t1: String,
t2: String,
) {
}
}
0.36.0id("org.jlleitschuh.gradle.ktlint") version "9.2.1" (Gradle plugin)5.6.4Actually it is already supported in Kotlin 1.3.70, see https://youtrack.jetbrains.com/issue/KT-34743
Probably requires to set kotlinOptions.targetVersion to 1.4
Also related to #709
This is still not resolved on my code, what was the workaround?
@carbotaniuman
I have configured the version manually (because the plugin pulled in 0.35.0) and the issue went away:
in my build.gradle.kts:
kotlin {
ktlint("0.40.0")
}
Thanks!
While what @rethab suggests most likely will work, if your project determines the ktlint version via
org.jlleitschuh.gradle:ktlint-gradle, then, there's currently a PR open in that repo that's attempting to update their default ktlint version to 0.40.0.
Once this PR goes in, the other option to fix this issue would be updating org.jlleitschuh.gradle:ktlint-gradle to the latest version.
This way there aren't two places where the dependencies for the ktlint version is defined in your project.
Cheers!
@yuesaka-m you don't need to wait for ktlint-gradle new release, just set ktlint version to 0.40.0 via ktlint-gradle configuration.
@Tapchicoma oh great, didn't know that configuration option existed, thanks!
Most helpful comment
@yuesaka-m you don't need to wait for
ktlint-gradlenew release, just set ktlint version to0.40.0viaktlint-gradleconfiguration.