Skip to content

Commit e1057d7

Browse files
author
Vincent Potucek
committed
[prone] Apply errorprone
1 parent ffb7c59 commit e1057d7

File tree

11 files changed

+106
-23
lines changed

11 files changed

+106
-23
lines changed

gradle/error-prone.gradle

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,91 @@ dependencies {
1818

1919
tasks.withType(JavaCompile).configureEach {
2020
options.errorprone {
21-
disableAllChecks = true // consider removal to avoid error prone error´s, following convention over configuration.
22-
error('RedundantStringConversion')
21+
disable( // not patchable
22+
'FormatStringConcatenation',
23+
'FunctionalInterfaceMethodChanged',
24+
'JavaxInjectOnAbstractMethod',
25+
'OverridesJavaxInjectableMethod',
26+
'ReturnValueIgnored',
27+
'Slf4jLogStatement',
28+
'MissingSummary',
29+
// patchable
30+
'ConstantNaming', // fixed: https://github.com/diffplug/spotless/pull/2687
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+
)
42+
error(
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+
// 'LexicographicalAnnotationAttributeListing',
57+
// 'LexicographicalAnnotationListing',
58+
'MockitoMockClassReference',
59+
'MockitoStubbing',
60+
'NestedOptionals',
61+
'PrimitiveComparison',
62+
'RedundantStringConversion',
63+
'RedundantStringEscape',
64+
'SelfAssignment',
65+
'StringJoin',
66+
'StringJoining',
67+
)
68+
// fixme bug: this only happens when the file is dirty!
69+
// up2date checking (caching) must consider file changes, as file is currently corrupt!
70+
// fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
71+
errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java')
2372
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
2473
errorproneArgs.addAll(
2574
'-XepPatchLocation:IN_PLACE',
26-
'-XepPatchChecks:RedundantStringConversion'
75+
'-XepPatchChecks:' +
76+
'AmbiguousJsonCreator,' +
77+
'ArrayEquals,' +
78+
'AssertJNullnessAssertion,' +
79+
'AutowiredConstructor,' +
80+
'CanonicalAnnotationSyntax,' +
81+
'CollectorMutability,' +
82+
// 'ConstantNaming,' +
83+
'DirectReturn,' +
84+
'EmptyMethod,' +
85+
'ExplicitArgumentEnumeration,' +
86+
'ExplicitEnumOrdering,' +
87+
'FormatStringConcatenation,' +
88+
'IdentityConversion,' +
89+
'ImmutablesSortedSetComparator,' +
90+
'IsInstanceLambdaUsage,' +
91+
// 'LexicographicalAnnotationAttributeListing,' +
92+
// 'LexicographicalAnnotationListing,' +
93+
'MockitoMockClassReference,' +
94+
'MockitoStubbing,' +
95+
'NestedOptionals,' +
96+
// 'NonStaticImport,' +
97+
'PrimitiveComparison,' +
98+
'RedundantStringConversion,' +
99+
'RedundantStringEscape,' +
100+
'SelfAssignment,' +
101+
'Slf4jLogStatement,' +
102+
// 'StaticImport,' +
103+
'StringJoin,' +
104+
'StringJoining,' +
105+
'TimeZoneUsage,'
27106
)
28107
}
29108
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 DiffPlug
2+
* Copyright 2024-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.
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.ObjectOutputStream;
2222
import java.io.Serializable;
23+
import java.util.Arrays;
2324
import java.util.List;
2425

2526
import org.junit.jupiter.api.Assertions;
@@ -43,7 +44,7 @@ public void test() throws Exception {
4344

4445
var serialized1 = toBytes(step1);
4546
var serialized2 = toBytes(step2);
46-
Assertions.assertFalse(serialized1.equals(serialized2));
47+
Assertions.assertFalse(Arrays.equals(serialized1, serialized2));
4748
}
4849

4950
private static FormatterStep withSettingsFile(File settingsFile) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-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.
@@ -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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.nio.file.attribute.PosixFilePermission;
2626
import java.util.ArrayList;
2727
import java.util.HashSet;
28-
import java.util.Set;
2928

3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
@@ -299,7 +298,7 @@ private State createState() throws IOException, InterruptedException {
299298
validateBiomeExecutable(resolvedPathToExe);
300299
validateBiomeConfigPath(configPath, version);
301300
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
302-
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
301+
var exeSignature = FileSignature.signAsList(new File(resolvedPathToExe));
303302
makeExecutable(resolvedPathToExe);
304303
return new State(resolvedPathToExe, exeSignature, configPath, language);
305304
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.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.
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-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.
@@ -59,7 +59,7 @@ void beforeEach() throws Exception {
5959

6060
@Test
6161
void deletesExistingIndexFileWhenCreated() {
62-
Log log = mock(Log.class);
62+
Log log = mock();
6363
try (UpToDateChecker realChecker = UpToDateChecker.forProject(project, indexFile, singletonList(dummyFormatter()), log)) {
6464
realChecker.setUpToDate(existingSourceFile);
6565
}
@@ -76,7 +76,7 @@ void deletesExistingIndexFileWhenCreated() {
7676
void doesNothingWhenIndexFileDoesNotExist() {
7777
assertThat(indexFile).doesNotExist();
7878

79-
Log log = mock(Log.class);
79+
Log log = mock();
8080
try (UpToDateChecker noopChecker = UpToDateChecker.noop(project, indexFile, log)) {
8181
assertThat(noopChecker).isNotNull();
8282
}

0 commit comments

Comments
 (0)