Skip to content

Adding a space before a comment makes method chaining appear as multi-line in Gradle #517

@robifr

Description

@robifr

Adding a comment with a single space (the space is important) at the end of a method chain in a Gradle build script will cause the code to be incorrectly formatted, making it appear as multi-line or folded instead of staying on one line.

Expected behavior:
Place this code at the very end of build.gradle.kts. Even an empty file containing only this code can reproduce the bug.

tasks.named("preBuild").dependsOn("test")

//


Actual behavior:
Inside build.gradle.kts

tasks
    .named("preBuild")
    .dependsOn(
        "test")

// Removing this comment will make the formatting work as expected.


I tested this on an Android project using Spotless with Gradle.

My root build.gradle.kts

allprojects {
  apply<SpotlessPlugin>()
  extensions.configure<SpotlessExtension> {
    kotlinGradle {
      target("*.gradle.kts")
      ktfmt()
    }  
    ...
}
$ ./gradlew spotlessApply

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions