diffplug / diffplug/spotless

ktlint: Formatting does not converge when line is long and formatted code needs a trailing comma

Offen
#1,689 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug-unconfirmed
Vorherrschende Sprache
Java
Sterne
5.6k
Forks
559
Ø Merge
1 T. 14 Std.
Gemergte PRs (30 T.)
43

Beschreibung

I originally filed this to ktlint at https://github.com/pinterest/ktlint/issues/1979 but it seems like it's likely a spotless issue. So copying in from there.

## Expected Behavior

Code formats

## Observed Behavior

Failure with `trailing-comma-on-call-site`

## Steps to Reproduce

```
errorprone {
excludedPaths.set(".*com.google.protobuf.util.*|.*org.curioswitch.common.protobuf.json.test.*")
}
```

If this line is too long based on editorconfig values, then it is supposed to reformat to split lines and have a trailing comma

```
errorprone {
excludedPaths.set(
".*com.google.protobuf.util.*|.*org.curioswitch.common.protobuf.json.test.*",
)
}
```

However, instead it gives an error

```
Step 'ktlint' found problem in 'build.gradle.kts':
Error on line: 64, column: 1
rule: trailing-comma-on-call-site
Missing trailing comma before ")"
```

It seems it is only applying the line length change without the trailing comma change. The error message is highly confusing too, because there is no expectation for a trailing comma in the original one-line code, only in the intermediate reformatted version.

We can see it in https://github.com/curioswitch/protobuf-jackson/pull/14, running `spotlessApply` in this repo with the change will still fail with that error message instead of reformatting.

If manually reformatting, then it passes. Had no idea where the error is, I guess the line number is also wrong, referring to the intermediate reformatted version and not the original?

## Your Environment

* Version of ktlint used:
Default in gradle-spotless-plugin
* Relevant parts of the `.editorconfig` settings
`max_line_length = 100`
* Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
gradle-spotless-plugin: 6.18.0
* Version of Gradle used (if applicable): 7.3.3
* Operating System and version: Mac OS X 13.2.1

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Reproduziere das Problem in build.gradle.kts mit Gradle Spotless 6.18.0, max_line_length = 100 und dem gezeigten errorprone-Block; beginne damit, spotlessApply auszuführen und die ktlint trailing-comma-on-call-site-Integration zu untersuchen. Erledigt ist die Aufgabe, wenn ein langer Aufruf in einem Durchlauf mit seinem abschließenden Komma neu formatiert wird, ohne einen irreführenden Fehler oder einen falschen Zeilenverweis.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
kotlin
Bereich
build-system, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.