Adding a space before a comment makes method chaining appear as multi-line in Gradle
- Dominant language
- Kotlin
- Stars
- 1.3k
- Forks
- 116
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 15
Description
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.
```kt
tasks.named("preBuild").dependsOn("test")
//
```
\
**Actual behavior**:
Inside `build.gradle.kts`
```kt
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`
```kt
allprojects {
apply()
extensions.configure {
kotlinGradle {
target("*.gradle.kts")
ktfmt()
}
...
}
```
```bash
$ ./gradlew spotlessApply
```
Contributor guide
Research direction
Reproduce the formatter issue with the minimal snippet at the end of build.gradle.kts, then run ./gradlew spotlessApply using the root build.gradle.kts configuration shown. Trace how the trailing single-space comment affects method-chain formatting, and consider the issue done when the chain remains on one line while the comment is present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100