diffplug / diffplug/spotless

imports broken by whitespace over at least two lines cannot be parsed

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

説明

Gradle 7.6.1
Spotless 6.25.0
Ubuntu 22.04
Java 11 or 17

Our code is:
```
import static foo.bar.
FooClass.CONSTANT;
```

The import class package is very very long so it's broken across multiple lines, but I believe any import will reproduce the issue.

The spotless stacktrace is:
```
Step 'removeUnusedImports' found problem in 'path/to/offending/file.java':
14:84: error: expected
com.google.googlejavaformat.java.FormatterException: 14:84: error: expected
at com.google.googlejavaformat.java.FormatterException.fromJavacDiagnostics(FormatterException.java:51)
at com.google.googlejavaformat.java.RemoveUnusedImports.parse(RemoveUnusedImports.java:264)
at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:218)
at com.diffplug.spotless.glue.java.GoogleJavaFormatRemoveUnusedImporterFormatterFunc.apply(GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java:38)
```

Using `toggleOffOn()` with `// spotless:off` and `// spotless:on` around the offending import(s) makes no difference because the code cannot be parsed.

Gradle plugin block:
```
spotless {
enforceCheck false
java {
toggleOffOn()
target 'src/**/*.java'
encoding 'UTF-8'
lineEndings 'UNIX'
importOrderFile("/path/to/import-order-file")
removeUnusedImports()
}
}
```
My workaround at the moment is to add:
```
targetExclude 'path/to/offending/file.java'
```
to our gradle plugin config.

At a minimum the `toggleOffOn()` should work but in theory, since this is legal java, the parser should be able to deal with it and it should just work.

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

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

調査の方向性

issue に示されている Gradle 設定と複数行 import で失敗を再現し、その後、スタックトレース内の RemoveUnusedImports.parse と removeUnusedImports から調査を開始してください。toggleOffOn と targetExclude での動作を比較してください。完了とは、報告された parse エラーなしで正当な複数行 import が処理され、ドキュメント化された設定が期待どおりに動作することです。

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

評価

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

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

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