Skip to content

Commit 8228fe0

Browse files
author
Vincent Potucek
committed
[prone] Add ConstantNaming
1 parent 68c1254 commit 8228fe0

File tree

41 files changed

+202
-195
lines changed

Some content is hidden

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

41 files changed

+202
-195
lines changed

gradle/error-prone.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ dependencies {
1919
tasks.withType(JavaCompile).configureEach {
2020
options.errorprone {
2121
disableAllChecks = true // consider removal to avoid error prone error´s, following convention over configuration.
22-
error('RedundantStringConversion')
22+
error(
23+
'ConstantNaming',
24+
'RedundantStringConversion',
25+
)
2326
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
2427
errorproneArgs.addAll(
2528
'-XepPatchLocation:IN_PLACE',
26-
'-XepPatchChecks:RedundantStringConversion'
29+
'-XepPatchChecks:' +
30+
'ConstantNaming,' +
31+
'RedundantStringConversion,'
2732
)
2833
}
2934
}

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/DirtyState.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 DiffPlug
2+
* Copyright 2022-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.
@@ -31,19 +31,18 @@
3131
* then you can call {@link #writeCanonicalTo(OutputStream)} to get the canonical form of the given file.
3232
*/
3333
public class DirtyState {
34-
@Nullable
35-
private final byte[] canonicalBytes;
34+
@Nullable private final byte[] canonicalBytes;
3635

3736
DirtyState(@Nullable byte[] canonicalBytes) {
3837
this.canonicalBytes = canonicalBytes;
3938
}
4039

4140
public boolean isClean() {
42-
return this == isClean;
41+
return this == IS_CLEAN;
4342
}
4443

4544
public boolean didNotConverge() {
46-
return this == didNotConverge;
45+
return this == DID_NOT_CONVERGE;
4746
}
4847

4948
byte[] canonicalBytes() {
@@ -63,11 +62,11 @@ public void writeCanonicalTo(OutputStream out) throws IOException {
6362

6463
/** Returns the DirtyState which corresponds to {@code isClean()}. */
6564
public static DirtyState clean() {
66-
return isClean;
65+
return IS_CLEAN;
6766
}
6867

69-
static final DirtyState didNotConverge = new DirtyState(null);
70-
static final DirtyState isClean = new DirtyState(null);
68+
static final DirtyState DID_NOT_CONVERGE = new DirtyState(null);
69+
static final DirtyState IS_CLEAN = new DirtyState(null);
7170

7271
public static DirtyState of(Formatter formatter, File file) throws IOException {
7372
return of(formatter, file, Files.readAllBytes(file.toPath()));
@@ -101,7 +100,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw
101100
// if F(input) == input, then the formatter is well-behaving and the input is clean
102101
byte[] formattedBytes = formatted.getBytes(formatter.getEncoding());
103102
if (Arrays.equals(rawBytes, formattedBytes)) {
104-
return isClean;
103+
return IS_CLEAN;
105104
}
106105

107106
// F(input) != input, so we'll do a padded check
@@ -113,7 +112,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw
113112

114113
PaddedCell cell = PaddedCell.check(formatter, file, rawUnix, exceptionPerStep);
115114
if (!cell.isResolvable()) {
116-
return didNotConverge;
115+
return DID_NOT_CONVERGE;
117116
}
118117

119118
// get the canonical bytes
@@ -124,7 +123,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw
124123
// and write them to disk if needed
125124
return new DirtyState(canonicalBytes);
126125
} else {
127-
return isClean;
126+
return IS_CLEAN;
128127
}
129128
}
130129
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private FileSignature(final List<File> files) throws IOException {
9393

9494
int i = 0;
9595
for (File file : this.files) {
96-
signatures[i] = cache.sign(file);
96+
signatures[i] = CACHE.sign(file);
9797
++i;
9898
}
9999
}
@@ -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. */
@@ -179,7 +179,7 @@ private static List<File> validateInputFiles(List<File> files) {
179179
* the jars which constitute any given formatter live in a central cache, but will be signed
180180
* over and over. To save this I/O, we maintain a cache, invalidated by lastModified time.
181181
*/
182-
static final Cache cache = new Cache();
182+
static final Cache CACHE = new Cache();
183183

184184
private static final class Cache {
185185
Map<String, Sig> cache = new HashMap<>();

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)