diffplug / diffplug/spotless

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

オープン
#1,689 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug-unconfirmed
主要言語
Java
スター
5.6k
フォーク
559
平均マージ
1日 14時間
マージ済み PR(30日)
43

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Gradle Spotless 6.18.0、max_line_length = 100、そして示されている errorprone ブロックを使って build.gradle.kts で問題を再現し、まず spotlessApply を実行して ktlint trailing-comma-on-call-site 統合を調査します。長い呼び出しが末尾のカンマ付きで一度の処理で再フォーマットされ、誤解を招く失敗や不正な行参照が発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
kotlin
領域
build-system, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。