Skip to content

ktlint appears to be reading from the File not the String #1599

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

Closed
3 tasks
auguwu opened this issue Feb 28, 2023 · 3 comments · Fixed by #2302
Closed
3 tasks

ktlint appears to be reading from the File not the String #1599

auguwu opened this issue Feb 28, 2023 · 3 comments · Fixed by #2302
Labels

Comments

@auguwu
Copy link

auguwu commented Feb 28, 2023

This issue is present in only Kotlin/Kotlin (Gradle) file source sets that I know of with the ktlint formatter.

When a source file is changed, the license doesn't reflect the changes and marks the file as an OK state, which should update the license content if it was changed.

A reproduction repository can be seen in auguwu/spotless-kotlin/repro. Just run ./gradlew spotlessApply.

Expected Result

/**
 * some example of license content here
 * Copyright (c) 2023
 */

import kotlin.TODO

fun main(args: Array<String>) {
    println(

        "we do a little" +

            "trolling",
    )

    TODO("this function is a work in progress!")
}

Actual Result

import kotlin.TODO

fun main(args: Array<String>) {
    println(

        "we do a little" +

            "trolling",
    )

    TODO("this function is a work in progress!")
}
  • Gradle: 7.6 ~ 8.0.1
  • Spotless: 6.14.0 ~ 6.16.0
  • Operating System (from uname -a): Linux [redacted] 6.1.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Tue, 14 Feb 2023 22:08:08 +0000 x86_64 GNU/Linux
@nedtwigg
Copy link
Member

A workaround is to move the licenseHeaderFile to the bottom of the kotlin block. But this indicates a deeper bug where the ktlint integration is violating Spotless' composability contract. Thanks for reporting, this is a medium-deal bug in the ktlint formatter which we will definitely fix.

@nedtwigg nedtwigg changed the title License(s) not being updated in Kotlin / Kotlin Gradle files ktlint appears to be reading from the File not the String Feb 28, 2023
@nedtwigg
Copy link
Member

This bug is definitely present in the default ktlint version of plugin-gradle 6.16.0.

@nedtwigg
Copy link
Member

Fixed in plugin-gradle 7.0.0.BETA4 and plugin-maven 2.44.0.BETA4.

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

Successfully merging a pull request may close this issue.

2 participants