Skip to content

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

Description

@auguwu

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

Activity

  1. nedtwigg commented on Feb 28, 2023

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

  2. changed the title [-]License(s) not being updated in Kotlin / Kotlin Gradle files[/-] [+]ktlint appears to be reading from the `File` not the `String`[/+] on Feb 28, 2023
  3. nedtwigg commented on Feb 28, 2023

    @nedtwigg
    Member

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

  4. nedtwigg commented on Oct 24, 2024

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions