Skip to content

Commit abac3db

Browse files
author
Vincent Potucek
committed
Add ConstantNaming
1 parent 68c1254 commit abac3db

File tree

35 files changed

+176
-168
lines changed

35 files changed

+176
-168
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/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;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ synchronized ClassLoader classloader(Serializable key, JarState state) {
7676
}
7777

7878
static SpotlessCache instance() {
79-
return instance;
79+
return INSTANCE;
8080
}
8181

8282
/**
8383
* Closes all cached classloaders.
8484
*/
8585
private static void clear() {
8686
List<URLClassLoader> toDelete;
87-
synchronized (instance) {
88-
toDelete = new ArrayList<>(instance.cache.values());
89-
instance.cache.clear();
87+
synchronized (INSTANCE) {
88+
toDelete = new ArrayList<>(INSTANCE.cache.values());
89+
INSTANCE.cache.clear();
9090
}
9191
for (URLClassLoader classLoader : toDelete) {
9292
try {
@@ -104,7 +104,7 @@ private static void clear() {
104104
* If {@code key} is null, the clear will always happen (as though null != null).
105105
*/
106106
public static boolean clearOnce(@Nullable Object key) {
107-
synchronized (instance) {
107+
synchronized (INSTANCE) {
108108
if (key == null) {
109109
lastClear = null;
110110
} else if (key.equals(lastClear)) {
@@ -117,5 +117,5 @@ public static boolean clearOnce(@Nullable Object key) {
117117
return true;
118118
}
119119

120-
private static final SpotlessCache instance = new SpotlessCache();
120+
private static final SpotlessCache INSTANCE = new SpotlessCache();
121121
}

0 commit comments

Comments
 (0)