diffplug / diffplug/spotless

Spotless confuses real code with simulated code in unit tests

Abierto
#2,997 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
5.6k
Forks
559
Merge medio
1 d 14 h
PR fusionados (30 d)
43

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con OrderImportsCustomTest.java en la línea 83 y reproduce el informe usando las versiones 3.6.0, 3.7.0 y 3.8.0 del Spotless Maven plugin. Rastrea por qué el Java text block se trata como source code durante el comando check y, a continuación, verifica que el import simulado se ignore mientras que los wildcard imports reales sigan notificándose.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
build-system
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.