Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin 1.4 trailing commas marked as invalid syntax #729

Closed
vanshg opened this issue Apr 22, 2020 · 7 comments
Closed

Kotlin 1.4 trailing commas marked as invalid syntax #729

vanshg opened this issue Apr 22, 2020 · 7 comments

Comments

@vanshg
Copy link

vanshg commented Apr 22, 2020

Expected Behavior

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

Observed Behavior

ktlint throws the following error:
Not a valid Kotlin file (expecting a parameter declaration) (cannot be auto-corrected)

Steps to Reproduce

Run ktlint on the following contents

data class Test(
    val test1: String,
    val test2: String,
) {
    fun test(
        t1: String,
        t2: String,
    ) {

    }
}

Your Environment

  • Version of ktlint used: 0.36.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): id("org.jlleitschuh.gradle.ktlint") version "9.2.1" (Gradle plugin)
  • Version of Gradle used (if applicable): 5.6.4
  • Operating System and version: macOS 10.15.2
  • Link to your project (if it's a public repository): https://github.com/airmap/AirMapSDK-Kotlin/
@vanshg vanshg changed the title Kotlin 1.4 trailing commas marked as invalid Kotlin file Kotlin 1.4 trailing commas marked as invalid syntax Apr 22, 2020
@Tapchicoma
Copy link
Collaborator

Actually 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

@carbotaniuman
Copy link

This is still not resolved on my code, what was the workaround?

@rethab
Copy link

rethab commented Dec 15, 2020

@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")
}

@carbotaniuman
Copy link

Thanks!

@yuesaka-m
Copy link

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!

@Tapchicoma
Copy link
Collaborator

@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.

@yuesaka-m
Copy link

@Tapchicoma oh great, didn't know that configuration option existed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants