Skip to content

Commit 9f7af1f

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

File tree

13 files changed

+107
-85
lines changed

13 files changed

+107
-85
lines changed

gradle/error-prone.gradle

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,88 @@ apply plugin: 'net.ltgt.errorprone'
55
dependencies {
66
errorprone('com.google.errorprone:error_prone_core:2.42.0')
77
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.25.0')
8-
constraints {
9-
errorprone('com.google.guava:guava') {
10-
version {
11-
require('33.4.8-jre')
12-
}
13-
because('Older versions use deprecated methods in sun.misc.Unsafe')
14-
// https://github.com/junit-team/junit-framework/pull/5039#discussion_r2414490581
15-
}
16-
}
178
}
189

1910
tasks.withType(JavaCompile).configureEach {
2011
options.errorprone {
21-
disableAllChecks = true // consider removal to avoid error prone error´s, following convention over configuration.
12+
disable( // not patchable
13+
'FormatStringConcatenation',
14+
'FunctionalInterfaceMethodChanged',
15+
'JavaxInjectOnAbstractMethod',
16+
'OverridesJavaxInjectableMethod',
17+
'ReturnValueIgnored',
18+
'Slf4jLogStatement',
19+
'MissingSummary',
20+
// patchable
21+
'LexicographicalAnnotationAttributeListing',
22+
'LexicographicalAnnotationListing',
23+
'NonStaticImport',
24+
'Slf4jLoggerDeclaration', // logger -> log
25+
'StaticImport',
26+
// critical, finds lots of bugs... unused configs and stuff.
27+
'Unused',
28+
'UnusedMethod',
29+
'UnusedParameters',
30+
'UnusedVariable',
31+
)
2232
error(
33+
'AmbiguousJsonCreator',
34+
'AssertJNullnessAssertion',
35+
'AutowiredConstructor',
36+
'CanonicalAnnotationSyntax',
37+
'CollectorMutability',
2338
'ConstantNaming',
39+
'DirectReturn',
40+
'EmptyMethod',
41+
'ExplicitArgumentEnumeration',
42+
'ExplicitEnumOrdering',
43+
'IdentityConversion',
44+
'ImmutablesSortedSetComparator',
45+
'IsInstanceLambdaUsage',
46+
'MockitoMockClassReference',
47+
'MockitoStubbing',
48+
'NestedOptionals',
49+
'PrimitiveComparison',
2450
'RedundantStringConversion',
51+
'RedundantStringEscape',
52+
'SelfAssignment',
53+
'StringJoin',
54+
'StringJoining',
2555
)
56+
// fixme bug: this only happens when the file is dirty!
57+
// up2date checking (caching) must consider file changes, as file is currently corrupt!
58+
// fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
59+
errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java')
2660
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
2761
errorproneArgs.addAll(
2862
'-XepPatchLocation:IN_PLACE',
2963
'-XepPatchChecks:' +
64+
'AmbiguousJsonCreator,' +
65+
'ArrayEquals,' +
66+
'AssertJNullnessAssertion,' +
67+
'AutowiredConstructor,' +
68+
'CanonicalAnnotationSyntax,' +
69+
'CollectorMutability,' +
3070
'ConstantNaming,' +
31-
'RedundantStringConversion,'
71+
'DirectReturn,' +
72+
'EmptyMethod,' +
73+
'ExplicitArgumentEnumeration,' +
74+
'ExplicitEnumOrdering,' +
75+
'FormatStringConcatenation,' +
76+
'IdentityConversion,' +
77+
'ImmutablesSortedSetComparator,' +
78+
'IsInstanceLambdaUsage,' +
79+
'MockitoMockClassReference,' +
80+
'MockitoStubbing,' +
81+
'NestedOptionals,' +
82+
'PrimitiveComparison,' +
83+
'RedundantStringConversion,' +
84+
'RedundantStringEscape,' +
85+
'SelfAssignment,' +
86+
'Slf4jLogStatement,' +
87+
'StringJoin,' +
88+
'StringJoining,' +
89+
'TimeZoneUsage,'
3290
)
3391
}
3492
}

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
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public GradleRunner gradleRunner() throws IOException {
5858

5959
@ParameterizedTest
6060
//@ValueSource(ints = {0, 1}) // TODO: this is a flaky configuration cache issue that started with Gradle 8.5
61-
@ValueSource(ints = {0})
61+
@ValueSource(ints = 0)
6262
void singleProjectExhaustive(int useConfigCache) throws Exception {
6363
try (Git git = initRepo()) {
6464
if (useConfigCache == 1) {
@@ -158,7 +158,7 @@ private BuildResultAssertion assertFail(String... tasks) throws Exception {
158158

159159
@ParameterizedTest
160160
//@ValueSource(ints = {0, 1}) // TODO: this is a flaky configuration cache issue that started with Gradle 8.5
161-
@ValueSource(ints = {0})
161+
@ValueSource(ints = 0)
162162
void multiProject(int useConfigCache) throws Exception {
163163
try (Git git = initRepo()) {
164164
if (useConfigCache == 1) {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
public class SpotlessTaskImplTest {
3030
@Test
3131
public void testThrowsMessageContainsFilename() throws Exception {
32-
SpotlessTaskImpl task = Mockito.mock(SpotlessTaskImpl.class, Mockito.CALLS_REAL_METHODS);
32+
SpotlessTaskImpl task = Mockito.mock(Mockito.CALLS_REAL_METHODS);
3333
Mockito.when(task.getLogger()).thenReturn(Mockito.mock(Logger.class));
3434

3535
File projectDir = Path.of("unitTests", "projectDir").toFile();
36-
DirectoryProperty projectDirProperty = Mockito.mock(DirectoryProperty.class, Mockito.RETURNS_DEEP_STUBS);
36+
DirectoryProperty projectDirProperty = Mockito.mock(Mockito.RETURNS_DEEP_STUBS);
3737
Mockito.when(projectDirProperty.get().getAsFile()).thenReturn(projectDir);
3838

3939
Mockito.when(task.getProjectDir()).thenReturn(projectDirProperty);
4040

4141
File input = Path.of("unitTests", "projectDir", "someInput").toFile();
42-
Formatter formatter = Mockito.mock(Formatter.class);
42+
Formatter formatter = Mockito.mock();
4343

4444
Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input, "someInput")).hasMessageContaining(input.toString());
4545
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/FileLocatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FileLocatorTest extends ResourceHarness {
4040

4141
@BeforeEach
4242
void beforeEach() {
43-
resourceManager = mock(ResourceManager.class);
43+
resourceManager = mock();
4444
fileLocator = new FileLocator(resourceManager, rootFolder(), rootFolder());
4545
}
4646

plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/FileIndexHarness.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ abstract class FileIndexHarness {
3535

3636
protected static final PluginFingerprint FINGERPRINT = PluginFingerprint.from("foo");
3737

38-
protected final FileIndexConfig config = mock(FileIndexConfig.class);
39-
protected final Log log = mock(Log.class);
38+
protected final FileIndexConfig config = mock();
39+
protected final Log log = mock();
4040

4141
protected Path tempDir;
4242

0 commit comments

Comments
 (0)