Skip to content

Commit 0347af7

Browse files
author
Vincent Potucek
committed
Issue #2634: Add StreamRulesRecipes
1 parent 792d0f2 commit 0347af7

File tree

8 files changed

+29
-15
lines changed

8 files changed

+29
-15
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313
cancel-in-progress: true
1414
jobs:
1515
sanityCheck:
16-
name: spotlessCheck assemble testClasses
16+
name: spotlessCheck rewriteDryRun assemble testClasses
1717
runs-on: ubuntu-latest
1818
env:
1919
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
@@ -31,6 +31,8 @@ jobs:
3131
uses: gradle/actions/setup-gradle@v4
3232
- name: spotlessCheck
3333
run: ./gradlew spotlessCheck
34+
- name: rewriteDryRun
35+
run: ./gradlew rewriteDryRun
3436
- name: assemble testClasses
3537
run: ./gradlew assemble testClasses
3638
build:
@@ -66,10 +68,10 @@ jobs:
6668
uses: gradle/actions/setup-gradle@v4
6769
- name: build (maven-only)
6870
if: matrix.kind == 'maven'
69-
run: ./gradlew :plugin-maven:build -x spotlessCheck
71+
run: ./gradlew :plugin-maven:build -x spotlessCheck -x rewriteDryRun
7072
- name: build (everything-but-maven)
7173
if: matrix.kind == 'gradle'
72-
run: ./gradlew build -x spotlessCheck -PSPOTLESS_EXCLUDE_MAVEN=true
74+
run: ./gradlew build -x spotlessCheck -x rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
7375
- name: test npm
7476
if: matrix.kind == 'npm'
7577
run: ./gradlew testNpm

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2727
### Added
2828
* Add a `lint` mode to `ReplaceRegexStep` ([#2571](https://github.com/diffplug/spotless/pull/2571))
2929
* `LintSuppression` now enforces unix-style paths in its `setPath` and `relativizeAsUnix` methods. ([#2629](https://github.com/diffplug/spotless/pull/2629))
30+
* Add `rewrite` support ([#2588](https://github.com/diffplug/spotless/pull/2588))
3031

3132
## [3.3.1] - 2025-07-21
3233
### Fixed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repositories {
1212
apply from: rootProject.file('gradle/java-publish.gradle')
1313
apply from: rootProject.file('gradle/changelog.gradle')
1414
allprojects {
15+
apply from: rootProject.file('gradle/rewrite.gradle')
1516
apply from: rootProject.file('gradle/spotless.gradle')
1617
}
1718
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
@@ -27,3 +28,7 @@ spotless {
2728
endWithNewline()
2829
}
2930
}
31+
32+
dependencies {
33+
rewrite("org.openrewrite.recipe:rewrite-third-party:0.27.0")
34+
}

gradle/rewrite.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apply plugin: 'org.openrewrite.rewrite'
2+
3+
rewrite {
4+
activeRecipe("tech.picnic.errorprone.refasterrules.StreamRulesRecipes")
5+
exportDatatables = true
6+
failOnDryRunResults = true
7+
}

lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,10 @@
1818
import static java.util.Objects.requireNonNull;
1919

2020
import java.io.File;
21-
import java.util.*;
21+
import java.util.ArrayList;
22+
import java.util.Arrays;
23+
import java.util.List;
24+
import java.util.Optional;
2225
import java.util.function.Function;
2326
import java.util.function.Predicate;
2427
import java.util.function.Supplier;
@@ -44,8 +47,8 @@ Optional<File> tryFind() {
4447
.stream()
4548
.map(Supplier::get)
4649
.filter(Optional::isPresent)
47-
.map(Optional::get)
48-
.findFirst();
50+
.findFirst()
51+
.map(Optional::get);
4952
}
5053

5154
static class Builder {

lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ public boolean isLayoutPrepared() {
8181
if (!packageLockJsonFile.isFile()) {
8282
return false;
8383
}
84-
if (!serveJsFile().isFile()) {
85-
return false;
86-
}
87-
// npmrc is optional, so must not be checked here
88-
return true;
84+
return serveJsFile().isFile(); // npmrc is optional, so must not be checked here
8985
}
9086

9187
public boolean isNodeModulesPrepared() {
@@ -96,7 +92,7 @@ public boolean isNodeModulesPrepared() {
9692
// check if it is NOT empty
9793
return ThrowingEx.get(() -> {
9894
try (Stream<Path> entries = Files.list(nodeModulesInstallDirPath)) {
99-
return entries.findFirst().isPresent();
95+
return entries.findAny().isPresent();
10096
}
10197
});
10298
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ private List<FormatterFactory> getFormatterFactories() {
414414
}
415415

416416
private List<FormatterStepFactory> getFormatterStepFactories() {
417-
return Stream.of(licenseHeader)
418-
.filter(Objects::nonNull)
417+
return Stream.ofNullable(licenseHeader)
419418
.collect(toList());
420419
}
421420

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ plugins {
2323
id 'com.gradle.develocity' version '3.19.2'
2424
// https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md
2525
id 'dev.equo.ide' version '1.7.8' apply false
26+
id 'org.openrewrite.rewrite' version '7.16.0' apply false
2627
}
2728

2829
dependencyResolutionManagement {

0 commit comments

Comments
 (0)