diffplug / diffplug/spotless

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

Aperta
#2,106 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
5.6k
Fork
559
Merge medio
1g 14h
PR unite (30g)
43

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci il fallimento con la configurazione Gradle e l’import multilinea mostrati nell’issue, quindi parti da RemoveUnusedImports.parse e removeUnusedImports nello stack trace. Confronta il comportamento con toggleOffOn e targetExclude; il lavoro è completato quando gli import multilinea validi vengono gestiti senza l’errore di parsing segnalato e la configurazione documentata si comporta come previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
build-system, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.