Skip to content

Commit 557f4dd

Browse files
author
Vincent Potucek
committed
[openrewrite] add tech.picnic.errorprone.refasterrules
1 parent 02b623d commit 557f4dd

File tree

44 files changed

+126
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+126
-75
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ spotless {
3232
dependencies {
3333
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.14.1"))
3434
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.18.0")
35+
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.17.0')
36+
rewrite('org.openrewrite.recipe:rewrite-third-party:0.27.0')
3537
}

gradle/rewrite.gradle

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
apply plugin: 'org.openrewrite.rewrite'
22

33
rewrite {
4-
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
4+
activeRecipe(
5+
'org.openrewrite.gradle.GradleBestPractices',
6+
'org.openrewrite.java.RemoveUnusedImports',
7+
'org.openrewrite.java.migrate.UpgradeToJava17',
8+
'org.openrewrite.staticanalysis.LowercasePackage',
9+
'org.openrewrite.staticanalysis.MissingOverrideAnnotation',
10+
'org.openrewrite.staticanalysis.ModifierOrder',
11+
'org.openrewrite.staticanalysis.NoFinalizer',
12+
'org.openrewrite.staticanalysis.RemoveUnusedLocalVariables',
13+
'org.openrewrite.staticanalysis.RemoveUnusedPrivateFields',
14+
'org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods',
15+
'tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes',
16+
'tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes',
17+
'tech.picnic.errorprone.refasterrules.ClassRulesRecipes',
18+
'tech.picnic.errorprone.refasterrules.CollectionRulesRecipes',
19+
'tech.picnic.errorprone.refasterrules.ComparatorRulesRecipes',
20+
'tech.picnic.errorprone.refasterrules.FileRulesRecipes',
21+
'tech.picnic.errorprone.refasterrules.MicrometerRulesRecipes',
22+
'tech.picnic.errorprone.refasterrules.PatternRulesRecipes',
23+
'tech.picnic.errorprone.refasterrules.PreconditionsRulesRecipes',
24+
'tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes',
25+
'tech.picnic.errorprone.refasterrules.StreamRulesRecipes',
26+
'tech.picnic.errorprone.refasterrules.TimeRulesRecipes'
27+
)
28+
exclusions.addAll(
29+
'**_gradle_node_plugin_example_**',
30+
'**gradle/changelog.gradle',
31+
'**gradle/java-publish.gradle',
32+
'**lib-extra/build.gradle',
33+
'**lib/build.gradle',
34+
'**package-info.java',
35+
'**plugin-maven/build.gradle',
36+
'**settings.gradle'
37+
)
538
exportDatatables = true
639
failOnDryRunResults = true
740
}

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static class CachedEndings implements Serializable {
146146
private static final long serialVersionUID = -2534772773057900619L;
147147

148148
/** this is transient, to simulate PathSensitive.RELATIVE */
149-
transient final String rootDir;
149+
final transient String rootDir;
150150
/** the line ending used for most files */
151151
final String defaultEnding;
152152
/** any exceptions to that default, in terms of relative path from rootDir */

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

Lines changed: 4 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.
@@ -132,9 +132,9 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) {
132132
return treeWalk.idEqual(TREE, WORKDIR);
133133
}
134134

135-
private final static int TREE = 0;
136-
private final static int INDEX = 1;
137-
private final static int WORKDIR = 2;
135+
private static final int TREE = 0;
136+
private static final int INDEX = 1;
137+
private static final int WORKDIR = 2;
138138

139139
Map<File, Repository> gitRoots = new HashMap<>();
140140
Table<Repository, String, ObjectId> rootTreeShaCache = HashBasedTable.create();

lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static Map.Entry<Integer, String> diff(Path rootDir, Formatter formatter,
251251
}
252252

253253
private static Map.Entry<Integer, String> diff(CleanProvider formatter, File file) throws IOException {
254-
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
254+
String raw = Files.readString(file.toPath(), formatter.getEncoding());
255255
String rawUnix = LineEnding.toUnix(raw);
256256
String formatted = formatter.getFormatted(file, rawUnix);
257257
String formattedUnix = LineEnding.toUnix(formatted);

lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-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.
@@ -24,8 +24,8 @@
2424
import com.diffplug.spotless.extra.eclipse.EquoResourceHarness;
2525

2626
public class GrEclipseFormatterStepTest extends EquoResourceHarness {
27-
private final static String INPUT = "class F{ def m(){} }";
28-
private final static String EXPECTED = "class F{\n\tdef m(){}\n}";
27+
private static final String INPUT = "class F{ def m(){} }";
28+
private static final String EXPECTED = "class F{\n\tdef m(){}\n}";
2929

3030
public GrEclipseFormatterStepTest() {
3131
super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()));

lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-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.
@@ -19,6 +19,7 @@
1919
import java.io.FileOutputStream;
2020
import java.io.IOException;
2121
import java.io.OutputStream;
22+
import java.nio.file.Files;
2223
import java.util.Properties;
2324
import java.util.function.Consumer;
2425
import java.util.stream.Stream;
@@ -33,7 +34,7 @@
3334
import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness;
3435

3536
public class EclipseWtpFormatterStepTest {
36-
private final static Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");
37+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");
3738

3839
private static class NestedTests extends EclipseResourceHarness {
3940
private final String unformatted, formatted;
@@ -76,7 +77,7 @@ void multipleConfigurations() throws Exception {
7677
private File createPropertyFile(Consumer<Properties> config) throws IOException {
7778
Properties configProps = new Properties();
7879
config.accept(configProps);
79-
File tempFile = File.createTempFile("EclipseWtpFormatterStepTest-", ".properties");
80+
File tempFile = Files.createTempFile("EclipseWtpFormatterStepTest-", ".properties").toFile();
8081
OutputStream tempOut = new FileOutputStream(tempFile);
8182
configProps.store(tempOut, "test properties");
8283
tempOut.flush();

lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected Class<?> inferType(String input) {
5252
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
5353
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>
5454
*/
55+
@Override
5556
protected JsonFactory makeJsonFactory() {
5657
JsonFactory jsonFactory = new JsonFactoryBuilder().build();
5758

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static FormatterProperties fromXmlContent(final Iterable<String> content)
113113

114114
public static FormatterProperties merge(Properties... properties) {
115115
FormatterProperties merged = new FormatterProperties();
116-
List.of(properties).stream().forEach((source) -> merged.properties.putAll(source));
116+
List.of(properties).forEach((source) -> merged.properties.putAll(source));
117117
return merged;
118118
}
119119

lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void doInstall() throws Exception {
172172
* such as file reading or writing errors
173173
*/
174174
private void uninstall(File gitHookFile) throws Exception {
175-
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
175+
final var hook = Files.readString(gitHookFile.toPath());
176176
final int hookStart = hook.indexOf(HOOK_HEADER);
177177
final int hookEnd = hook.indexOf(HOOK_FOOTER) + HOOK_FOOTER.length(); // hookEnd exclusive, so must be last symbol \n
178178

@@ -323,7 +323,7 @@ private boolean isGitInstalled() {
323323
* @throws Exception if an error occurs when reading the file.
324324
*/
325325
private boolean isGitHookInstalled(File gitHookFile) throws Exception {
326-
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
326+
final var hook = Files.readString(gitHookFile.toPath());
327327
return hook.contains(HOOK_HEADER) && hook.contains(HOOK_FOOTER);
328328
}
329329

0 commit comments

Comments
 (0)