Spotless confuses real code with simulated code in unit tests

オープン
#2,997 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

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

調査の方向性

OrderImportsCustomTest.java の83行目から始め、Spotless Maven plugin のバージョン 3.6.0、3.7.0、3.8.0 を使って報告を再現します。check コマンド中に Java text block が source code として扱われる理由を追跡し、その後、実際の wildcard imports は引き続き報告される一方で、シミュレートされた import が無視されることを確認します。

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

説明

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
主要言語
Java
スター
5.7k
フォーク
560
平均マージ
1日 13時間
マージ済み PR(30日)
43

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

diffplug/spotless のほかの issue

diffplug/spotless の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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