Skip to content

Commit df2a886

Browse files
authored
[openrewrite] add tech.picnic.errorprone.refasterrules (#2641)
2 parents 180d678 + 28b3e65 commit df2a886

File tree

45 files changed

+143
-78
lines changed

Some content is hidden

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

45 files changed

+143
-78
lines changed

.github/workflows/claude.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@ jobs:
2222
with:
2323
script: |
2424
try {
25+
// Get username - prioritize sender (the person who triggered the event)
26+
const username = github.event.sender?.login ||
27+
github.event.comment?.user?.login;
28+
29+
if (!username) {
30+
console.log('Could not determine username from event payload');
31+
console.log(`Event type: ${github.event_name}`);
32+
console.log(`Event payload keys: ${Object.keys(github.event).join(', ')}`);
33+
return false;
34+
}
35+
36+
console.log(`Checking team membership for user: ${username} (triggered by ${github.event_name} event)`);
37+
2538
const { data } = await github.rest.teams.getMembershipForUserInOrg({
2639
org: 'diffplug',
2740
team_slug: 'spotless',
28-
username: github.event.sender.login
41+
username: username
2942
});
30-
console.log(`User ${github.event.sender.login} membership status: ${data.state}`);
43+
console.log(`User ${username} membership status: ${data.state}`);
3144
return data.state === 'active';
3245
} catch (error) {
33-
console.log(`User ${github.event.sender.login} is not a member of the Spotless team`);
46+
const username = github.event.sender?.login || github.event.comment?.user?.login || 'unknown user';
47+
console.log(`User ${username} is not a member of the Spotless team or error occurred: ${error.message}`);
3448
return false;
3549
}
3650

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.15.0"))
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

0 commit comments

Comments
 (0)