Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 11 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Comment on lines +39 to +41
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//'org.openrewrite.staticanalysis.CodeCleanup', bug
//'org.openrewrite.staticanalysis.CommonStaticAnalysis', bug
//'org.openrewrite.staticanalysis.UnnecessaryThrows', bug

these include most others and should be the final goal.

)
exclusions.addAll(
'**_gradle_node_plugin_example_**',
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static class CachedEndings implements Serializable {

CachedEndings(File projectDir, Runtime runtime, Iterable<File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}
Expand All @@ -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;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static FormatterProperties fromXmlContent(final Iterable<String> 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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -332,7 +332,7 @@ private List<Node> 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;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/Jvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ private void verifyVersionRangesDoNotIntersect(NavigableMap<Integer, V> 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);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/LintSuppression.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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`.");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/MoreIterables.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private MoreIterables() {}
/** Returns a shallow copy of input elements, throwing on null elements. */
static <T> List<T> toNullHostileList(Iterable<T> input) {
requireElementsNonNull(input);
List<T> shallowCopy = (input instanceof Collection<?> c)
List<T> shallowCopy = input instanceof Collection<?> c
? new ArrayList<>(c.size())
: new ArrayList<>();
input.forEach(shallowCopy::add);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/ProcessRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public Result(@Nonnull List<String> 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<String> args() {
Expand Down
14 changes: 7 additions & 7 deletions lib/src/main/java/com/diffplug/spotless/biome/Architecture.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private List<String> 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;
Expand All @@ -217,7 +217,7 @@ private List<String> getResult(List<String> sortedImported, String lineFormat) {
List<String> 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);
Expand Down Expand Up @@ -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<String>, Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static class ParentOfNodeModulesDirResolver implements Function<File, File> {

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')");
}
Expand Down Expand Up @@ -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<Object> resources = new ArrayList<>();
while (hasNext(resIterator)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading