diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index c750cbde0b..6e7dbc6435 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -23,8 +23,8 @@ jobs: script: | try { // Get username - prioritize sender (the person who triggered the event) - const username = github.event.sender?.login || - github.event.comment?.user?.login; + const username = github.event?.sender?.login || + github.event?.comment?.user?.login; if (!username) { console.log('Could not determine username from event payload'); diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle index 965ad177fb..04d554371d 100644 --- a/gradle/rewrite.gradle +++ b/gradle/rewrite.gradle @@ -4,18 +4,26 @@ rewrite { activeRecipe( 'org.openrewrite.gradle.GradleBestPractices', 'org.openrewrite.java.RemoveUnusedImports', + 'org.openrewrite.java.format.RemoveTrailingWhitespace', 'org.openrewrite.java.migrate.UpgradeToJava17', 'org.openrewrite.java.recipes.JavaRecipeBestPractices', 'org.openrewrite.java.recipes.RecipeTestingBestPractices', 'org.openrewrite.java.security.JavaSecurityBestPractices', + 'org.openrewrite.staticanalysis.EqualsAvoidsNull', 'org.openrewrite.staticanalysis.JavaApiBestPractices', 'org.openrewrite.staticanalysis.LowercasePackage', 'org.openrewrite.staticanalysis.MissingOverrideAnnotation', 'org.openrewrite.staticanalysis.ModifierOrder', 'org.openrewrite.staticanalysis.NoFinalizer', + 'org.openrewrite.staticanalysis.NoToStringOnStringType', + 'org.openrewrite.staticanalysis.NoValueOfOnStringType', 'org.openrewrite.staticanalysis.RemoveUnusedLocalVariables', 'org.openrewrite.staticanalysis.RemoveUnusedPrivateFields', 'org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods', + 'org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources', + 'org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments', + 'org.openrewrite.staticanalysis.UnnecessaryParentheses', + 'org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement', 'tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes', 'tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes', 'tech.picnic.errorprone.refasterrules.ClassRulesRecipes', @@ -28,6 +36,9 @@ rewrite { 'tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes', 'tech.picnic.errorprone.refasterrules.StreamRulesRecipes', 'tech.picnic.errorprone.refasterrules.TimeRulesRecipes' + //'org.openrewrite.staticanalysis.CodeCleanup', bug + //'org.openrewrite.staticanalysis.CommonStaticAnalysis', bug + //'org.openrewrite.staticanalysis.UnnecessaryThrows', bug ) exclusions.addAll( '**_gradle_node_plugin_example_**', diff --git a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java index 78791e240b..6611827dc2 100644 --- a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java +++ b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 DiffPlug + * Copyright 2024-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -368,8 +368,8 @@ private boolean isSortPreserved(BodyDeclaration bodyDeclaration) { } private int preserveRelativeOrder(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclaration2) { - int value1 = ((Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER)); - int value2 = ((Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER)); + int value1 = (Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER); + int value2 = (Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER); return value1 - value2; } diff --git a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java index 819168013f..7dfb99776b 100644 --- a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java +++ b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 DiffPlug + * Copyright 2024-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ && isInterfaceOrAnnotationMember(bodyDeclaration)) } private static boolean isPackageVisible(BodyDeclaration bodyDeclaration) { - return (!isPrivate(bodyDeclaration) && !isProtected(bodyDeclaration) && !isPublic(bodyDeclaration)); + return !isPrivate(bodyDeclaration) && !isProtected(bodyDeclaration) && !isPublic(bodyDeclaration); } private static boolean isPrivate(BodyDeclaration bodyDeclaration) { diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index f28eb5a338..9d6491f281 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -154,7 +154,7 @@ static class CachedEndings implements Serializable { CachedEndings(File projectDir, Runtime runtime, Iterable toFormat) { String rootPath = FileSignature.pathNativeToUnix(projectDir.getAbsolutePath()); - rootDir = rootPath.equals("/") ? rootPath : rootPath + "/"; + rootDir = "/".equals(rootPath) ? rootPath : rootPath + "/"; defaultEnding = runtime.defaultEnding; for (File file : toFormat) { String ending = runtime.getEndingFor(file); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index b68cb93bb4..fa29951a3e 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -69,8 +69,8 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce return (String) method.invoke(formatter, input); } catch (InvocationTargetException exceptionWrapper) { Throwable throwable = exceptionWrapper.getTargetException(); - Exception exception = (throwable instanceof Exception e) ? e : null; - throw (null == exception) ? exceptionWrapper : exception; + Exception exception = throwable instanceof Exception e ? e : null; + throw null == exception ? exceptionWrapper : exception; } }); } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 0daaefcd60..7cae8c942b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -97,8 +97,8 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce return (String) method.invoke(formatter, input); } catch (InvocationTargetException exceptionWrapper) { Throwable throwable = exceptionWrapper.getTargetException(); - Exception exception = (throwable instanceof Exception e) ? e : null; - throw (null == exception) ? exceptionWrapper : exception; + Exception exception = throwable instanceof Exception e ? e : null; + throw null == exception ? exceptionWrapper : exception; } }); } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index b5982dbf64..d2afcf9ac2 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -67,8 +67,8 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep return (String) method.invoke(formatter, input); } catch (InvocationTargetException exceptionWrapper) { Throwable throwable = exceptionWrapper.getTargetException(); - Exception exception = (throwable instanceof Exception e) ? e : null; - throw (null == exception) ? exceptionWrapper : exception; + Exception exception = throwable instanceof Exception e ? e : null; + throw null == exception ? exceptionWrapper : exception; } }; } @@ -85,8 +85,8 @@ public String applyWithFile(String unix, File file) throws Exception { return (String) method.invoke(formatter, unix, file.getAbsolutePath()); } catch (InvocationTargetException exceptionWrapper) { Throwable throwable = exceptionWrapper.getTargetException(); - Exception exception = (throwable instanceof Exception e) ? e : null; - throw (null == exception) ? exceptionWrapper : exception; + Exception exception = throwable instanceof Exception e ? e : null; + throw null == exception ? exceptionWrapper : exception; } } }); diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java b/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java index 3bd6498f97..6e75edafd0 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java @@ -114,7 +114,7 @@ public static FormatterProperties fromXmlContent(final Iterable content) public static FormatterProperties merge(Properties... properties) { FormatterProperties merged = new FormatterProperties(); - List.of(properties).forEach((source) -> merged.properties.putAll(source)); + List.of(properties).forEach(source -> merged.properties.putAll(source)); return merged; } @@ -300,7 +300,7 @@ protected Properties execute(InputStream file, Node rootNode) throws IOException * A missing value is interpreted as an empty string, * similar to the Properties behavior */ - String valString = (null == value) ? "" : value.getNodeValue(); + String valString = null == value ? "" : value.getNodeValue(); properties.setProperty(idString, valString); } return properties; @@ -332,7 +332,7 @@ private List getChildren(final Node node, final String nodeName) { private static String getProfileName(Node profile) { Node nameAttribute = profile.getAttributes().getNamedItem("name"); - return (null == nameAttribute) ? "" : nameAttribute.getNodeValue(); + return null == nameAttribute ? "" : nameAttribute.getNodeValue(); } private final String rootNodeName; diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 40b0b79c1a..e9fa881a3f 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -122,12 +122,12 @@ private void verifyVersionRangesDoNotIntersect(NavigableMap jvm2fmtV /** @return Highest formatter version recommended for this JVM (null, if JVM not supported) */ @Nullable public V getRecommendedFormatterVersion() { Integer configuredJvmVersionOrNull = jvm2fmtMaxVersion.floorKey(Jvm.version()); - return (null == configuredJvmVersionOrNull) ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull); + return null == configuredJvmVersionOrNull ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull); } @Nullable public V getMinimumRequiredFormatterVersion() { Integer configuredJvmVersionOrNull = jvm2fmtMinVersion.floorKey(Jvm.version()); - return (null == configuredJvmVersionOrNull) ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull); + return null == configuredJvmVersionOrNull ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/LintSuppression.java b/lib/src/main/java/com/diffplug/spotless/LintSuppression.java index b36cb2a0e7..9221fe089d 100644 --- a/lib/src/main/java/com/diffplug/spotless/LintSuppression.java +++ b/lib/src/main/java/com/diffplug/spotless/LintSuppression.java @@ -58,9 +58,9 @@ public void setShortCode(String shortCode) { } public boolean suppresses(String relativePath, FormatterStep formatterStep, Lint lint) { - if (path.equals(ALL) || path.equals(relativePath)) { - if (step.equals(ALL) || formatterStep.getName().equals(this.step)) { - if (shortCode.equals(ALL) || lint.getShortCode().equals(this.shortCode)) { + if (ALL.equals(path) || path.equals(relativePath)) { + if (ALL.equals(step) || formatterStep.getName().equals(this.step)) { + if (ALL.equals(shortCode) || lint.getShortCode().equals(this.shortCode)) { return true; } } @@ -69,7 +69,7 @@ public boolean suppresses(String relativePath, FormatterStep formatterStep, Lint } public void ensureDoesNotSuppressAll() { - boolean suppressAll = path.equals(ALL) && step.equals(ALL) && shortCode.equals(ALL); + boolean suppressAll = ALL.equals(path) && ALL.equals(step) && ALL.equals(shortCode); if (suppressAll) { throw new IllegalArgumentException("You must specify a specific `file`, `step`, or `shortCode`."); } diff --git a/lib/src/main/java/com/diffplug/spotless/MoreIterables.java b/lib/src/main/java/com/diffplug/spotless/MoreIterables.java index 22832aa678..3a03127184 100644 --- a/lib/src/main/java/com/diffplug/spotless/MoreIterables.java +++ b/lib/src/main/java/com/diffplug/spotless/MoreIterables.java @@ -31,7 +31,7 @@ private MoreIterables() {} /** Returns a shallow copy of input elements, throwing on null elements. */ static List toNullHostileList(Iterable input) { requireElementsNonNull(input); - List shallowCopy = (input instanceof Collection c) + List shallowCopy = input instanceof Collection c ? new ArrayList<>(c.size()) : new ArrayList<>(); input.forEach(shallowCopy::add); diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index c6dd44ca7b..39d07b5888 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -202,7 +202,7 @@ public Result(@Nonnull List args, int exitCode, @Nonnull byte[] stdOut, this.args = args; this.exitCode = exitCode; this.stdOut = stdOut; - this.stdErr = (stdErr == null ? new byte[0] : stdErr); + this.stdErr = stdErr == null ? new byte[0] : stdErr; } public List args() { diff --git a/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java index 29511842e2..a4791442ad 100644 --- a/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,22 +40,22 @@ public static Architecture guess() { var msg = "Unsupported architecture " + arch + "/" + version + ", specify the path to the Biome executable manually"; - if (arch.equals("ppc64le")) { + if ("ppc64le".equals(arch)) { throw new IllegalStateException(msg); } - if (arch.equals("s390x")) { + if ("s390x".equals(arch)) { throw new IllegalStateException(msg); } - if (arch.equals("ppc64")) { + if ("ppc64".equals(arch)) { throw new IllegalStateException(msg); } - if (arch.equals("ppc")) { + if ("ppc".equals(arch)) { throw new IllegalStateException(msg); } - if (arch.equals("aarch64")) { + if ("aarch64".equals(arch)) { return ARM64; } - if (arch.equals("arm")) { + if ("arm".equals(arch)) { if (version.contains("v7")) { throw new IllegalStateException(msg); } diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index a8df9b0a1d..91c51e8cbe 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -203,7 +203,7 @@ private List mergeMatchingItems() { } } // if there is \n on the end, remove it - if (!template.isEmpty() && template.get(template.size() - 1).equals(ImportSorter.N)) { + if (!template.isEmpty() && ImportSorter.N.equals(template.get(template.size() - 1))) { template.remove(template.size() - 1); } return template; @@ -217,7 +217,7 @@ private List getResult(List sortedImported, String lineFormat) { List strings = new ArrayList<>(); for (String s : sortedImported) { - if (s.equals(ImportSorter.N)) { + if (ImportSorter.N.equals(s)) { strings.add(s); } else { strings.add(lineFormat.formatted(s) + ImportSorter.N); @@ -264,7 +264,7 @@ private static int compareWithWildcare(String string1, String string2, boolean w if (!samePrefix) { return string1.compareTo(string2); } - return (string1IsWildcard == wildcardsLast) ? 1 : -1; + return string1IsWildcard == wildcardsLast ? 1 : -1; } private static class LexicographicalOrderingComparator implements Comparator, Serializable { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index c1aa695040..4f08bd21ce 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -109,7 +109,7 @@ static final class State implements Serializable { } FormatterFunc createFormat() throws Exception { - final File configFile = (config != null) ? config.getOnlyFile() : null; + final File configFile = config != null ? config.getOnlyFile() : null; Class formatterFunc = jar.getClassLoader().loadClass("com.diffplug.spotless.glue.diktat.DiktatFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( String.class, diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmExecutableResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmExecutableResolver.java index 4a06447407..1fc9ad324e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmExecutableResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmExecutableResolver.java @@ -65,7 +65,7 @@ static class ParentOfNodeModulesDirResolver implements Function { @Override public File apply(File file) { - if (file != null && file.isDirectory() && file.getName().equalsIgnoreCase("node_modules")) { + if (file != null && file.isDirectory() && "node_modules".equalsIgnoreCase(file.getName())) { return file.getParentFile(); } return file; diff --git a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java index 1979f99a1f..3260b28e1d 100644 --- a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java @@ -100,13 +100,13 @@ public ReflectionHelper(RdfFormatterStep.State state) this.TurtleFormatFormattingStyleClass = classLoader.loadClass("de.atextor.turtle.formatter.FormattingStyle"); Class[] innerClasses = TurtleFormatFormattingStyleClass.getDeclaredClasses(); this.TurtleFormatFormattingStyleBuilderClass = Arrays.stream(innerClasses) - .filter(c -> c.getSimpleName().equals("FormattingStyleBuilder")).findFirst().get(); - this.TurtleFormatKnownPrefix = Arrays.stream(innerClasses).filter(c -> c.getSimpleName().equals("KnownPrefix")).findFirst().get(); + .filter(c -> "FormattingStyleBuilder".equals(c.getSimpleName())).findFirst().get(); + this.TurtleFormatKnownPrefix = Arrays.stream(innerClasses).filter(c -> "KnownPrefix".equals(c.getSimpleName())).findFirst().get(); this.getSubject = JenaStatementClass.getMethod("getSubject"); this.getPredicate = JenaStatementClass.getMethod("getPredicate"); this.getObject = JenaStatementClass.getMethod("getObject"); this.isAnon = JenaRDFNodeClass.getMethod("isAnon"); - this.getGraph = JenaModelClass.getMethod(("getGraph")); + this.getGraph = JenaModelClass.getMethod("getGraph"); this.JenaGraphClass = classLoader.loadClass("org.apache.jena.graph.Graph"); this.JenaTriple = classLoader.loadClass("org.apache.jena.graph.Triple"); this.graphFindTriple = JenaGraphClass.getMethod("find", JenaTriple); @@ -201,10 +201,10 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl long line = (long) args[1]; long col = (long) args[2]; String severity = method.getName(); - if (severity.equals("warning") && !state.getConfig().isFailOnWarning()) { + if ("warning".equals(severity) && !state.getConfig().isFailOnWarning()) { logger.warn("{}({},{}): {}", this.filePath, line, col, message); } else { - if (severity.equals("warning")) { + if ("warning".equals(severity)) { logger.error("Formatter fails because of a parser warning. To make the formatter succeed in" + "the presence of warnings, set the configuration parameter 'failOnWarning' to 'false' (default: 'true')"); } @@ -503,7 +503,7 @@ public SortedModelInvocationHandler(ReflectionHelper reflectionHelper, Object je @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getName().equals("listSubjects") && method.getParameterCount() == 0) { + if ("listSubjects".equals(method.getName()) && method.getParameterCount() == 0) { Object resIterator = method.invoke(jenaModel); List resources = new ArrayList<>(); while (hasNext(resIterator)) { diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java index 58a0119a7f..02e236d4a4 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ public DBeaverSQLFormatterConfiguration(Properties properties) { } private String getIndentString(String indentType, int indentSize) { - char indentChar = indentType.equals("space") ? ' ' : '\t'; + char indentChar = "space".equals(indentType) ? ' ' : '\t'; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < indentSize; i++) { stringBuilder.append(indentChar); diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java index 01f0fd759e..03efa19dad 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,8 +124,8 @@ private List format(final List argList) { String token2String = t2.getString().toUpperCase(Locale.ENGLISH); // Concatenate tokens if (t0.getType() == TokenType.KEYWORD && t1.getType() == TokenType.SPACE && t2.getType() == TokenType.KEYWORD) { - if (((tokenString.equals("ORDER") || tokenString.equals("GROUP") || tokenString.equals("CONNECT")) && token2String.equals("BY")) || - ((tokenString.equals("START")) && token2String.equals("WITH"))) { + if ((("ORDER".equals(tokenString) || "GROUP".equals(tokenString) || "CONNECT".equals(tokenString)) && "BY".equals(token2String)) || + (("START".equals(tokenString)) && "WITH".equals(token2String))) { t0.setString(t0.getString() + " " + t2.getString()); argList.remove(index + 1); argList.remove(index + 1); @@ -133,14 +133,14 @@ private List format(final List argList) { } // Oracle style joins - if (tokenString.equals("(") && t1.getString().equals("+") && token2String.equals(")")) { //$NON-NLS-2$ //$NON-NLS-3$ + if ("(".equals(tokenString) && "+".equals(t1.getString()) && ")".equals(token2String)) { //$NON-NLS-2$ //$NON-NLS-3$ t0.setString("(+)"); argList.remove(index + 1); argList.remove(index + 1); } // JDBI bind list - if (tokenString.equals("<") && t1.getType() == TokenType.NAME && token2String.equals(">")) { + if ("<".equals(tokenString) && t1.getType() == TokenType.NAME && ">".equals(token2String)) { t0.setString(t0.getString() + t1.getString() + t2.getString()); argList.remove(index + 1); argList.remove(index + 1); @@ -155,16 +155,16 @@ private List format(final List argList) { token = argList.get(index); String tokenString = token.getString().toUpperCase(Locale.ENGLISH); if (token.getType() == TokenType.SYMBOL) { - if (tokenString.equals("(")) { + if ("(".equals(tokenString)) { functionBracket.add(isFunction(prev.getString()) ? Boolean.TRUE : Boolean.FALSE); bracketIndent.add(indent); indent++; index += insertReturnAndIndent(argList, index + 1, indent); - } else if (tokenString.equals(")") && !bracketIndent.isEmpty() && !functionBracket.isEmpty()) { + } else if (")".equals(tokenString) && !bracketIndent.isEmpty() && !functionBracket.isEmpty()) { indent = bracketIndent.remove(bracketIndent.size() - 1); index += insertReturnAndIndent(argList, index, indent); functionBracket.remove(functionBracket.size() - 1); - } else if (tokenString.equals(",")) { + } else if (",".equals(tokenString)) { index += insertReturnAndIndent(argList, index + 1, indent); } else if (statementDelimiters.contains(tokenString)) { indent = 0; @@ -292,10 +292,10 @@ private List format(final List argList) { FormatterToken t3 = argList.get(index - 3); FormatterToken t4 = argList.get(index - 4); - if (t4.getString().equals("(") + if ("(".equals(t4.getString()) && t3.getString().trim().isEmpty() && t1.getString().trim().isEmpty() - && t0.getString().equalsIgnoreCase(")")) { + && ")".equalsIgnoreCase(t0.getString())) { t4.setString(t4.getString() + t2.getString() + t0.getString()); argList.remove(index); argList.remove(index - 1); @@ -311,11 +311,11 @@ private List format(final List argList) { if (prev.getType() != TokenType.SPACE && token.getType() != TokenType.SPACE && !token.getString().startsWith("(")) { - if (token.getString().equals(",") || statementDelimiters.contains(token.getString())) { + if (",".equals(token.getString()) || statementDelimiters.contains(token.getString())) { continue; } if (isFunction(prev.getString()) - && token.getString().equals("(")) { + && "(".equals(token.getString())) { continue; } if (token.getType() == TokenType.VALUE && prev.getType() == TokenType.NAME) { @@ -373,7 +373,7 @@ private boolean isJoinStart(List argList, int index) { if (token.getType() == TokenType.SPACE) { continue; } - if (token.getString().equals("JOIN")) { + if ("JOIN".equals(token.getString())) { return true; } if (!contains(JOIN_BEGIN, token.getString())) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIncrementalResolutionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIncrementalResolutionTest.java index 69360b74ef..e26c6cc148 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIncrementalResolutionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIncrementalResolutionTest.java @@ -136,7 +136,7 @@ private AbstractStringAssert checkRanAgainstNoneButError() throws IOException private String taskRanAgainst(String task, String... ranAgainst) throws IOException { pauseForFilesystem(); String console = StringPrinter.buildString(Errors.rethrow().wrap(printer -> { - boolean expectFailure = task.equals("spotlessCheck") && !isClean(); + boolean expectFailure = "spotlessCheck".equals(task) && !isClean(); if (expectFailure) { gradleRunner().withArguments(task).forwardStdOutput(printer.toWriter()).forwardStdError(printer.toWriter()).buildAndFail(); } else { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 36efe4e7ab..7c2894b76a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -91,7 +91,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return new AbstractMap.SimpleEntry<>(entry.getKey(), Boolean.parseBoolean(entry.getValue())); } // Prettier v3 - plugins config will be a comma delimited list of plugins - if (entry.getKey().equals("plugins")) { + if ("plugins".equals(entry.getKey())) { List values = entry.getValue().isEmpty() ? List.of() : Arrays.asList(entry.getValue().split(",")); return new AbstractMap.SimpleEntry<>(entry.getKey(), values); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 4e7a977174..cd135605dc 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -313,7 +313,7 @@ protected static Map buildPomXmlParams(String pluginVersion, Str private static String getSystemProperty(String name) { if (SPOTLESS_MAVEN_VERSION_IDE != null) { - if (name.equals("spotlessMavenPluginVersion")) { + if ("spotlessMavenPluginVersion".equals(name)) { return SPOTLESS_MAVEN_VERSION_IDE; } else { throw Unhandled.stringException(name); diff --git a/testlib/src/main/resources/java/idea/full.dirty.java b/testlib/src/main/resources/java/idea/full.dirty.java index 83923130e6..d1c0a48cd7 100644 --- a/testlib/src/main/resources/java/idea/full.dirty.java +++ b/testlib/src/main/resources/java/idea/full.dirty.java @@ -9,7 +9,7 @@ @ SpringBootApplication -public +public class Application{ diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterPropertiesTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterPropertiesTest.java index 027404901c..3c7c174f9b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterPropertiesTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterPropertiesTest.java @@ -208,7 +208,7 @@ public FormatterSettingsAssert containsSpecificValuesOf(File file) { Properties settingsProps = actual.getProperties(); for (String expectedValue : VALID_VALUES) { // A parsable (valid) file contains keys of the following format - String validValueName = (null == expectedValue) ? "null" : expectedValue; + String validValueName = null == expectedValue ? "null" : expectedValue; String key = "%s.%s".formatted(fileName, validValueName); if (!settingsProps.containsKey(key)) { failWithMessage("Key <%s> not part of formatter settings.", key); diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index a05de28411..0057c814eb 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -142,7 +142,7 @@ void supportProposesFormatterUpgrade() { }).getMessage(); assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + - "My Test Formatter 2 requires JVM " + (requiredJvm) + "+."); + "My Test Formatter 2 requires JVM " + requiredJvm + "+."); } }