Skip to content

Commit adebb76

Browse files
author
Vincent Potucek
committed
[prone] Apply errorprone
1 parent 49203e8 commit adebb76

File tree

19 files changed

+138
-97
lines changed

19 files changed

+138
-97
lines changed

gradle/error-prone.gradle

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,86 @@ dependencies {
1717
}
1818

1919
tasks.withType(JavaCompile).configureEach {
20+
2021
options.errorprone {
21-
disableAllChecks = true // consider removal to avoid error prone error´s, following convention over configuration.
22+
disable( // not patchable
23+
'FormatStringConcatenation',
24+
'FunctionalInterfaceMethodChanged',
25+
'JavaxInjectOnAbstractMethod',
26+
'OverridesJavaxInjectableMethod',
27+
'ReturnValueIgnored',
28+
'Slf4jLogStatement',
29+
'MissingSummary',
30+
// patchable
31+
'LexicographicalAnnotationAttributeListing',
32+
'LexicographicalAnnotationListing',
33+
'NonStaticImport',
34+
'Slf4jLoggerDeclaration', // logger -> log
35+
'StaticImport',
36+
// critical, finds lots of bugs... unused configs and stuff.
37+
'Unused',
38+
'UnusedMethod',
39+
'UnusedParameters',
40+
'UnusedVariable',
41+
)
2242
error(
23-
'ConstantNaming',
43+
'AmbiguousJsonCreator',
44+
'AssertJNullnessAssertion',
45+
'AutowiredConstructor',
46+
'CanonicalAnnotationSyntax',
47+
'CollectorMutability',
48+
'ConstantNaming',
49+
'DirectReturn',
50+
'EmptyMethod',
51+
'ExplicitArgumentEnumeration',
52+
'ExplicitEnumOrdering',
53+
'IdentityConversion',
54+
'ImmutablesSortedSetComparator',
55+
'IsInstanceLambdaUsage',
56+
'MockitoMockClassReference',
57+
'MockitoStubbing',
58+
'NestedOptionals',
59+
'PrimitiveComparison',
2460
'RedundantStringConversion',
61+
'RedundantStringEscape',
62+
'SelfAssignment',
63+
'StringJoin',
64+
'StringJoining',
2565
)
66+
// fixme bug: this only happens when the file is dirty!
67+
// up2date checking (caching) must consider file changes, as file is currently corrupt!
68+
// fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
69+
errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java')
2670
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
2771
errorproneArgs.addAll(
2872
'-XepPatchLocation:IN_PLACE',
2973
'-XepPatchChecks:' +
30-
'ConstantNaming,' +
31-
'RedundantStringConversion,'
74+
'AmbiguousJsonCreator,' +
75+
'ArrayEquals,' +
76+
'AssertJNullnessAssertion,' +
77+
'AutowiredConstructor,' +
78+
'CanonicalAnnotationSyntax,' +
79+
'CollectorMutability,' +
80+
'ConstantNaming,' +
81+
'DirectReturn,' +
82+
'EmptyMethod,' +
83+
'ExplicitArgumentEnumeration,' +
84+
'ExplicitEnumOrdering,' +
85+
'FormatStringConcatenation,' +
86+
'IdentityConversion,' +
87+
'ImmutablesSortedSetComparator,' +
88+
'IsInstanceLambdaUsage,' +
89+
'MockitoMockClassReference,' +
90+
'MockitoStubbing,' +
91+
'NestedOptionals,' +
92+
'PrimitiveComparison,' +
93+
'RedundantStringConversion,' +
94+
'RedundantStringEscape,' +
95+
'SelfAssignment,' +
96+
'Slf4jLogStatement,' +
97+
'StringJoin,' +
98+
'StringJoining,' +
99+
'TimeZoneUsage,'
32100
)
33101
}
34102
}

gradle/rewrite.gradle

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

33
rewrite {
44
activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck')
5-
activeStyle('com.diffplug.spotless.openrewrite.SpotlessFormat')
65
exclusions.addAll(
76
'**.dirty.java',
87
'**FormatterProperties.java',

lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtEqualityTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
*/
1616
package com.diffplug.spotless.extra.java;
1717

18+
import com.diffplug.spotless.FormatterStep;
19+
import com.diffplug.spotless.ResourceHarness;
20+
import com.diffplug.spotless.TestProvisioner;
21+
import com.diffplug.spotless.ThrowingEx;
1822
import java.io.ByteArrayOutputStream;
1923
import java.io.File;
2024
import java.io.IOException;
2125
import java.io.ObjectOutputStream;
2226
import java.io.Serializable;
27+
import java.util.Arrays;
2328
import java.util.List;
24-
2529
import org.junit.jupiter.api.Assertions;
2630
import org.junit.jupiter.api.Test;
2731

28-
import com.diffplug.spotless.FormatterStep;
29-
import com.diffplug.spotless.ResourceHarness;
30-
import com.diffplug.spotless.TestProvisioner;
31-
import com.diffplug.spotless.ThrowingEx;
32-
3332
public class EclipseJdtEqualityTest extends ResourceHarness {
3433
@Test
3534
public void test() throws Exception {
@@ -43,7 +42,7 @@ public void test() throws Exception {
4342

4443
var serialized1 = toBytes(step1);
4544
var serialized2 = toBytes(step2);
46-
Assertions.assertFalse(serialized1.equals(serialized2));
45+
Assertions.assertFalse(Arrays.equals(serialized1, serialized2));
4746
}
4847

4948
private static FormatterStep withSettingsFile(File settingsFile) {

lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public String format(
115115
private static EditorConfigOverride createEditorConfigOverride(final List<Rule> rules, Map<String, Object> editorConfigOverrideMap) {
116116
// Get properties from rules in the rule sets
117117
Stream<EditorConfigProperty<?>> ruleProperties = rules.stream()
118-
.filter(rule -> rule instanceof UsesEditorConfigProperties)
118+
.filter(UsesEditorConfigProperties.class::isInstance)
119119
.flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream());
120120

121121
// Create a mapping of properties to their names based on rule properties and default properties

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public String canonical() {
153153
// @formatter:off
154154
switch (type) {
155155
case CONVERGE: return steps.get(steps.size() - 1);
156-
case CYCLE: return Collections.min(steps, Comparator.comparing(String::length).thenComparing(Function.identity()));
156+
case CYCLE: return Collections.min(steps, Comparator.comparingInt(String::length).thenComparing(Function.identity()));
157157
case DIVERGE: throw new IllegalArgumentException("No canonical form for a diverging result");
158158
default: throw new IllegalArgumentException("Unknown type: " + type);
159159
}

lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private State createState() throws IOException, InterruptedException {
299299
validateBiomeExecutable(resolvedPathToExe);
300300
validateBiomeConfigPath(configPath, version);
301301
LOGGER.debug("Using Biome executable located at '{}'", resolvedPathToExe);
302-
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
302+
var exeSignature = FileSignature.signAsList(new File(resolvedPathToExe));
303303
makeExecutable(resolvedPathToExe);
304304
return new State(resolvedPathToExe, exeSignature, configPath, language);
305305
}

lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ private static String resolveFullBinaryPathAndCheckVersion(String binaryPath) {
158158
.pathToExe(pathToExe(binaryPath))
159159
.versionRegex(Pattern.compile("(IntelliJ IDEA) .*"))
160160
.fixCantFind(
161-
"IDEA executable cannot be found on your machine, "
162-
+ "please install it and put idea binary to PATH, provide a valid path to the executable or report the problem")
163-
.fixWrongVersion("Provided binary is not IDEA, "
164-
+ "please check it and fix the problem; or report the problem");
161+
"""
162+
IDEA executable cannot be found on your machine, \
163+
please install it and put idea binary to PATH, provide a valid path to the executable or report the problem""")
164+
.fixWrongVersion("""
165+
Provided binary is not IDEA, \
166+
please check it and fix the problem; or report the problem""");
165167
try {
166168
return exe.confirmVersionAndGetAbsolutePath();
167169
} catch (IOException e) {

lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ public FormatterStep create() {
6767
}
6868

6969
private RoundtripState createRountrip() throws IOException, InterruptedException {
70-
String howToInstall = "gofmt is a part of standard go distribution. If spotless can't discover it automatically, "
71-
+ "you can point Spotless to the go binary with {@code pathToExe('/path/to/go')}";
70+
String howToInstall = """
71+
gofmt is a part of standard go distribution. If spotless can't discover it automatically, \
72+
you can point Spotless to the go binary with {@code pathToExe('/path/to/go')}\
73+
""";
7274
final ForeignExe exe = ForeignExe.nameAndVersion("go", version)
7375
.pathToExe(pathToExe)
7476
.versionFlag("version")

lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
205205
LOGGER.warn("{}({},{}): {}", this.filePath, line, col, message);
206206
} else {
207207
if ("warning".equals(severity)) {
208-
LOGGER.error("Formatter fails because of a parser warning. To make the formatter succeed in"
209-
+ "the presence of warnings, set the configuration parameter 'failOnWarning' to 'false' (default: 'true')");
208+
LOGGER.error("""
209+
Formatter fails because of a parser warning. To make the formatter succeed in\
210+
the presence of warnings, set the configuration parameter 'failOnWarning' to 'false' (default: 'true')""");
210211
}
211212
throw new RuntimeException(
212213
"line %d, col %d: %s (severity: %s)".formatted(line, col, message, severity));

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ private static Provisioner forConfigurationContainer(Project project, Configurat
135135
projName = projName + "/";
136136
}
137137
throw new GradleException(String.format(
138-
"You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n"
139-
+ "E.g.: 'repositories { mavenCentral() }'",
138+
"""
139+
You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n\
140+
E.g.: 'repositories { mavenCentral() }'""",
140141
mavenCoords, projName), e);
141142
}
142143
};

0 commit comments

Comments
 (0)