imports broken by whitespace over at least two lines cannot be parsed
- Vorherrschende Sprache
- Java
- Sterne
- 5.6k
- Forks
- 559
- Ø Merge
- 1 T. 14 Std.
- Gemergte PRs (30 T.)
- 43
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Reproduziere den Fehler mit der in der Issue gezeigten Gradle-Konfiguration und dem mehrzeiligen Import und beginne dann bei RemoveUnusedImports.parse und removeUnusedImports im Stacktrace. Vergleiche das Verhalten mit toggleOffOn und targetExclude; fertig ist es, wenn gültige mehrzeilige Imports ohne den gemeldeten Parse-Fehler verarbeitet werden und sich die dokumentierte Konfiguration wie erwartet verhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- 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
- 45/100