Skip to content

Commit c8be894

Browse files
author
Vincent Potucek
committed
Add error-prone.picnic.tech featuring ConstantNaming
1 parent d3a160d commit c8be894

File tree

37 files changed

+243
-167
lines changed

37 files changed

+243
-167
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repositories {
1212
apply from: rootProject.file('gradle/java-publish.gradle')
1313
apply from: rootProject.file('gradle/changelog.gradle')
1414
allprojects {
15+
apply from: rootProject.file('gradle/error-prone.gradle')
1516
apply from: rootProject.file('gradle/rewrite.gradle')
1617
apply from: rootProject.file('gradle/spotless.gradle')
1718
}

gradle/error-prone.gradle

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import static java.lang.System.getenv
2+
3+
apply plugin: 'net.ltgt.errorprone'
4+
5+
dependencies {
6+
errorprone('com.google.errorprone:error_prone_core:2.42.0')
7+
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.25.0')
8+
errorprone('tech.picnic.error-prone-support:refaster-runner:0.25.0')
9+
constraints {
10+
errorprone('com.google.guava:guava') {
11+
version {
12+
require('33.4.8-jre')
13+
}
14+
because('Older versions use deprecated methods in sun.misc.Unsafe')
15+
// https://github.com/junit-team/junit-framework/pull/5039#discussion_r2414490581
16+
}
17+
}
18+
}
19+
20+
tasks.withType(JavaCompile).configureEach {
21+
options.errorprone {
22+
allErrorsAsWarnings = true // ModuleHelper.java:37: warning: Unsafe is internal proprietary API and may be removed in a future release
23+
errorproneArgs.add('-XepOpt:Refaster:NamePattern=^(?!.*Rules\\$).*')
24+
error(
25+
'ConstantNaming',
26+
'DirectReturn',
27+
// 'EmptyMethod',
28+
// 'EmptyMonoZip',
29+
// 'LexicographicalAnnotationAttributeListing',
30+
// 'LexicographicalAnnotationListing',
31+
// 'MissingOverride',
32+
// 'MissingTestCall',
33+
// 'NonEmptyMono',
34+
// 'NonStaticImport',
35+
// 'OptionalMapUnusedValue',
36+
// 'OptionalOfRedundantMethod',
37+
// 'RedundantSetterCall',
38+
// 'RedundantStringConversion',
39+
// 'RedundantStringEscape',
40+
// 'StaticImport',
41+
// 'StringJoin',
42+
// 'UnnecessaryCheckNotNull',
43+
// 'UnnecessaryTypeArgument',
44+
// 'UnusedAnonymousClass',
45+
// 'UnusedCollectionModifiedInPlace',
46+
)
47+
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
48+
errorproneArgs.addAll(
49+
'-XepPatchLocation:IN_PLACE',
50+
'-XepPatchChecks:' +
51+
'ConstantNaming,' +
52+
'DirectReturn,'
53+
// 'MissingOverride,' +
54+
// 'StaticImport,' +
55+
// EmptyMethod,' +
56+
// EmptyMonoZip,' +
57+
// LexicographicalAnnotationAttributeListing,' +
58+
// LexicographicalAnnotationListing,' +
59+
// MissingTestCall,' +
60+
// NonEmptyMono,' +
61+
// NonStaticImport,' +
62+
// OptionalMapUnusedValue,' +
63+
// OptionalOfRedundantMethod,' +
64+
// RedundantSetterCall,' +
65+
// RedundantStringConversion,' +
66+
// RedundantStringEscape,' +
67+
// StringJoin,' +
68+
// UnnecessaryCheckNotNull,' +
69+
// UnnecessaryTypeArgument,' +
70+
// UnusedAnonymousClass,' +
71+
// UnusedCollectionModifiedInPlace,'
72+
)
73+
}
74+
}
75+
}

lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.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.
@@ -55,7 +55,7 @@
5555

5656
public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter {
5757

58-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class);
58+
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class);
5959

6060
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6161

lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.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.
@@ -55,7 +55,7 @@
5555

5656
public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter {
5757

58-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class);
58+
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class);
5959

6060
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6161

lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.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.
@@ -54,7 +54,7 @@
5454

5555
public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter {
5656

57-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);
57+
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);
5858

5959
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6060

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ public File getOnlyFile() {
146146
}
147147
}
148148

149-
private static final boolean machineIsWin = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
149+
private static final boolean MACHINE_IS_WIN = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
150150

151151
/** Returns true if this JVM is running on a windows machine. */
152152
public static boolean machineIsWin() {
153-
return machineIsWin;
153+
return MACHINE_IS_WIN;
154154
}
155155

156156
/** Transforms a native path to a unix one. */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ static void legacyErrorBehavior(Formatter formatter, File file, ValuePerStep<Thr
143143
for (int i = 0; i < formatter.getSteps().size(); i++) {
144144
Throwable exception = exceptionPerStep.get(i);
145145
if (exception != null && exception != LintState.formatStepCausedNoChange()) {
146-
logger.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i).getName(), file.getName(), exception.getMessage(), exception);
146+
LOGGER.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i).getName(), file.getName(), exception.getMessage(), exception);
147147
throw ThrowingEx.asRuntimeRethrowError(exception);
148148
}
149149
}
150150
}
151151

152-
private static final Logger logger = LoggerFactory.getLogger(Formatter.class);
152+
private static final Logger LOGGER = LoggerFactory.getLogger(Formatter.class);
153153

154154
/**
155155
* Returns the result of calling all of the FormatterSteps, while also

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
*/
4646
public final class JarState implements Serializable {
4747

48-
private static final Logger logger = LoggerFactory.getLogger(JarState.class);
48+
private static final Logger LOGGER = LoggerFactory.getLogger(JarState.class);
4949

5050
// Let the classloader be overridden for tools using different approaches to classloading
5151
@Nullable private static ClassLoader forcedClassLoader;
5252

5353
/** Overrides the classloader used by all JarStates. */
5454
public static void setForcedClassLoader(@Nullable ClassLoader forcedClassLoader) {
5555
if (!Objects.equals(JarState.forcedClassLoader, forcedClassLoader)) {
56-
logger.info("Overriding the forced classloader for JarState from {} to {}", JarState.forcedClassLoader, forcedClassLoader);
56+
LOGGER.info("Overriding the forced classloader for JarState from {} to {}", JarState.forcedClassLoader, forcedClassLoader);
5757
}
5858
JarState.forcedClassLoader = forcedClassLoader;
5959
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Policy createPolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
8484
/** Should use {@link #createPolicy(File, Supplier)} instead, but this will work iff its a path-independent LineEnding policy. */
8585
public Policy createPolicy() {
8686
switch (this) {
87-
case PLATFORM_NATIVE: return _platformNativePolicy;
87+
case PLATFORM_NATIVE: return _PLATFORM_NATIVE_POLICY;
8888
case WINDOWS: return WINDOWS_POLICY;
8989
case UNIX: return UNIX_POLICY;
9090
case MAC_CLASSIC: return MAC_CLASSIC_POLICY;
@@ -152,9 +152,9 @@ static String getEndingFor(Reader reader) throws IOException {
152152
private static final Policy UNIX_POLICY = new ConstantLineEndingPolicy(UNIX.str());
153153
private static final Policy MAC_CLASSIC_POLICY = new ConstantLineEndingPolicy(MAC_CLASSIC.str());
154154
private static final Policy PRESERVE_POLICY = new PreserveLineEndingPolicy();
155-
private static final String _platformNative = System.getProperty("line.separator");
156-
private static final Policy _platformNativePolicy = new ConstantLineEndingPolicy(_platformNative);
157-
private static final boolean nativeIsWin = _platformNative.equals(WINDOWS.str());
155+
private static final String _PLATFORM_NATIVE = System.getProperty("line.separator");
156+
private static final Policy _PLATFORM_NATIVE_POLICY = new ConstantLineEndingPolicy(_PLATFORM_NATIVE);
157+
private static final boolean NATIVE_IS_WIN = _PLATFORM_NATIVE.equals(WINDOWS.str());
158158

159159
/**
160160
* @deprecated Using the system-native line endings to detect the windows operating system has turned out
@@ -164,13 +164,13 @@ static String getEndingFor(Reader reader) throws IOException {
164164
*/
165165
@Deprecated
166166
public static boolean nativeIsWin() {
167-
return nativeIsWin;
167+
return NATIVE_IS_WIN;
168168
}
169169

170170
/** Returns the standard line ending for this policy. */
171171
public String str() {
172172
switch (this) {
173-
case PLATFORM_NATIVE: return _platformNative;
173+
case PLATFORM_NATIVE: return _PLATFORM_NATIVE;
174174
case WINDOWS: return "\r\n";
175175
case UNIX: return "\n";
176176
case MAC_CLASSIC: return "\r";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ public static LintState of(Formatter formatter, File file, byte[] rawBytes) {
197197

198198
/** Returns the DirtyState which corresponds to {@code isClean()}. */
199199
public static LintState clean() {
200-
return isClean;
200+
return IS_CLEAN;
201201
}
202202

203-
private static final LintState isClean = new LintState(DirtyState.clean(), null);
203+
private static final LintState IS_CLEAN = new LintState(DirtyState.clean(), null);
204204

205205
static Throwable formatStepCausedNoChange() {
206206
return FormatterCausedNoChange.INSTANCE;

0 commit comments

Comments
 (0)