Spotless confuses real code with simulated code in unit tests

Aperta
#2,997 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
build-system

Direzione di ricerca

Inizia da OrderImportsCustomTest.java alla riga 83 e riproduci il report usando le versioni 3.6.0, 3.7.0 e 3.8.0 del Spotless Maven plugin. Traccia il motivo per cui il Java text block viene trattato come source code durante il comando check, quindi verifica che l’import simulato venga ignorato mentre i wildcard imports reali continuino a essere segnalati.

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

Descrizione

We have a project focused on the application of best practices and code correction using OpenRewrite. We have created a class to implement a custom Recipe that controls and corrects the use of the wildcard "*" in import groupings according to our internally defined standards.
We have a series of unit tests that use the testing libraries provided by OpenRewrite, in which we create code scenarios using string blocks:

 String before =
        """
        import java.util.List;
        import java.util.ArrayList;
        import java.util.regex.Pattern;
        import java.util.Objects;
        import java.util.Set;
        import java.util.Map;
        """;

    String after =
        """
        import java.util.*;
        import java.util.regex.Pattern;
        """;

    rewriteRun(java(before, after));

The problem is that when we run the check command for the Maven plugin com.diffplug.spotless:spotless-maven-plugin:3.8.0, Spotless detects these strings as if they were actual code, despite the use of triple quotes -> """ string code """.

OrderImportsCustomTest.java:L83 toggle(import java.util.*;) Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this

We have verified that this behavior only occurs in versions 3.7.0 and above. Version 3.6.0 correctly ignores this simulated code.
We have had to apply a workaround using // spotless:off, but we would like to know if there is a permanent solution to this behavior, which we believe is a false positive.

Poject Stack:

  • Java 25
  • Openrewrite 8.72.0
  • Spottles Maven Plugin 3.8.0
Lingua principale
Java
Stelle
5.7k
Fork
560
Merge medio
1g 13h
PR unite (30g)
43

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di diffplug/spotless

Tutte le issue di diffplug/spotless

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.