Skip to content
Closed
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ jobs:
matrix:
kind: [maven, gradle]
# Test on the latest Java version once Gradle & Maven support it.
jre: [17, 21, 24]
jre: [21, 24]
os: [ubuntu-latest, windows-latest]
include:
# npm on linux only (crazy slow on windows)
- kind: npm
jre: 17
jre: 21
os: ubuntu-latest
- kind: shfmt
jre: 17
jre: 21
os: ubuntu-latest
shfmt-version: v3.8.0
- kind: idea
jre: 17
jre: 21
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ artifactIdMaven=spotless-maven-plugin
artifactIdGradle=spotless-plugin-gradle

# Build requirements
VER_JAVA=17
VER_JAVA=21
VER_JSR_305=3.0.2

# Dependencies provided by Spotless plugin
Expand Down
2 changes: 1 addition & 1 deletion gradle/java-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ javadoc {
//
// Thus, no javadoc warnings.
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('source', '17')
options.addStringOption('source', '21')
// setup the header
options.header javadocInfo
// setup links
Expand Down
2 changes: 1 addition & 1 deletion gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava21")
exportDatatables = true
failOnDryRunResults = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void addFile(String arg) {
// ... (more lines that didn't fit)
List<String> lines = NEWLINE_SPLITTER.splitToList(arg);
if (!lines.isEmpty()) {
addIntendedLine(NORMAL_INDENT, lines.get(0));
addIntendedLine(NORMAL_INDENT, lines.getFirst());
}
for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); ++i) {
addIntendedLine(DIFF_INDENT, lines.get(i));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 DiffPlug
* Copyright 2022-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 All @@ -17,8 +17,6 @@

import java.lang.reflect.Field;
import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;

public interface KtLintCompatAdapter {
Expand All @@ -30,16 +28,13 @@ String format(
Map<String, Object> editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException;

static void setCodeContent(Object code, String content) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
Field contentField = code.getClass().getDeclaredField("content");
contentField.setAccessible(true);
contentField.set(code, content);
} catch (NoSuchFieldException | IllegalAccessException e) {
// Handle exceptions as needed
throw new RuntimeException("Failed to set content field", e);
}
return null;
});
try {
Field contentField = code.getClass().getDeclaredField("content");
contentField.setAccessible(true);
contentField.set(code, content);
} catch (NoSuchFieldException | IllegalAccessException e) {
// Handle exceptions as needed
throw new RuntimeException("Failed to set content field", e);
}
}
}
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Collection<File> files() {
/** Returns the only file in this signature, throwing an exception if there are more or less than 1 file. */
public File getOnlyFile() {
if (files.size() == 1) {
return files.iterator().next();
return files.getFirst();
} else {
throw new IllegalArgumentException("Expected one file, but was " + files.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private Node getSingleProfile(final Node rootNode) throws IllegalArgumentExcepti
message += "]%n The formatter can only cope with a single profile per configuration file. Please remove the other profiles.";
throw new IllegalArgumentException(message);
}
return profiles.iterator().next();
return profiles.getFirst();
}

private List<Node> getChildren(final Node node, final String nodeName) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/Jvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static <V> int[] convert(V versionObject) {
throw new IllegalArgumentException("Not a semantic version: %s".formatted(versionObject), e);
}
}
};
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/PaddedCell.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 @@ -152,7 +152,7 @@ public boolean isResolvable() {
public String canonical() {
// @formatter:off
switch (type) {
case CONVERGE: return steps.get(steps.size() - 1);
case CONVERGE: return steps.getLast();
case CYCLE: return Collections.min(steps, Comparator.comparing(String::length).thenComparing(Function.identity()));
case DIVERGE: throw new IllegalArgumentException("No canonical form for a diverging result");
default: throw new IllegalArgumentException("Unknown type: " + type);
Expand Down
34 changes: 12 additions & 22 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,32 +457,22 @@ private String resolveFileName(File file) {
}
var dot = name.lastIndexOf(".");
var ext = dot >= 0 ? name.substring(dot + 1) : name;
switch (language) {
case "js?":
return "jsx".equals(ext) || "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name
return switch (language) {
case "js?" -> "jsx".equals(ext) || "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name
: "file.js";
case "ts?":
return "tsx".equals(ext) || "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name
case "ts?" -> "tsx".equals(ext) || "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name
: "file.js";
case "js":
return "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name : "file.js";
case "jsx":
return "jsx".equals(ext) ? name : "file.jsx";
case "ts":
return "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name : "file.ts";
case "tsx":
return "tsx".equals(ext) ? name : "file.tsx";
case "json":
return "json".equals(ext) ? name : "file.json";
case "jsonc":
return "jsonc".equals(ext) ? name : "file.jsonc";
case "css":
return "css".equals(ext) ? name : "file.css";
case "js" -> "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name : "file.js";
case "jsx" -> "jsx".equals(ext) ? name : "file.jsx";
case "ts" -> "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name : "file.ts";
case "tsx" -> "tsx".equals(ext) ? name : "file.tsx";
case "json" -> "json".equals(ext) ? name : "file.json";
case "jsonc" -> "jsonc".equals(ext) ? name : "file.jsonc";
case "css" -> "css".equals(ext) ? name : "file.css";
// so that we can support new languages such as css or yaml when Biome adds
// support for them without having to change the code
default:
return "file." + language;
}
default -> "file." + language;
};
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 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 All @@ -21,13 +21,13 @@
/** Common utilities for C/C++ */
public class CppDefaults {
//Prevent instantiation
private CppDefaults() {};
private CppDefaults() {}

/**
* Default delimiter expression shall cover most valid and common starts of C/C++ declarations and definitions.
* Furthermore it shall not conflict with terms commonly used within license headers.
* Note that the longest match is selected. Hence "using namespace foo" is preferred over "namespace foo".
*/
* Default delimiter expression shall cover most valid and common starts of C/C++ declarations and definitions.
* Furthermore it shall not conflict with terms commonly used within license headers.
* Note that the longest match is selected. Hence "using namespace foo" is preferred over "namespace foo".
*/
public static final String DELIMITER_EXPR = Arrays.asList(
"#define", "#error", "#if", "#ifdef", "#ifndef", "#include", "#pragma", "#undef",
"asm", "class", "namespace", "struct", "typedef", "using namespace",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ private List<String> mergeMatchingItems() {
}
}
// if there is \n on the end, remove it
if (!template.isEmpty() && template.get(template.size() - 1).equals(ImportSorter.N)) {
template.remove(template.size() - 1);
if (!template.isEmpty() && template.getLast().equals(ImportSorter.N)) {
template.removeLast();
}
return template;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/npm/TimedLogger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-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 @@ -111,15 +111,15 @@ public final void close() {
}

private Object[] paramsForEnd() {
if (params.isEmpty() || !(params.get(params.size() - 1) instanceof Throwable)) {
if (params.isEmpty() || !(params.getLast() instanceof Throwable)) {
// if the last element is not a throwable, we can add the duration as the last element
return Stream.concat(params.stream(), Stream.of(lazy(this::durationString))).toArray();
}
// if the last element is a throwable, we have to add the duration before the last element
return Stream.concat(
params.stream().limit(params.size() - 1),
Stream.of(lazy(this::durationString),
params.get(params.size() - 1)))
params.getLast()))
.toArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private void callBuilderMethod(Object builder, Method method, String parameterVa
"Found more than 1 enum value for name %s, that should never happen".formatted(
parameterValueAsString));
}
method.invoke(builder, selectedEnumValueList.get(0));
method.invoke(builder, selectedEnumValueList.getFirst());
} else if (param.equals(NumberFormat.class)) {
method.invoke(builder, new DecimalFormat(parameterValueAsString, DecimalFormatSymbols.getInstance(Locale.US)));
} else if (param.equals(Boolean.class) || param.equals(Boolean.TYPE)) {
Expand Down Expand Up @@ -458,7 +458,7 @@ private Method getBuilderMethod(String optionName) {
"More than one builder method found for configuration parameter name: %s".formatted(
optionName));
}
Method method = methods.get(0);
Method method = methods.getFirst();
if (method.getParameterCount() != 1) {
throw new RuntimeException(
"Method with unexpected parameter count %s found for configuration parameter name: %s".formatted(
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 @@ -78,17 +78,17 @@ private List<FormatterToken> format(final List<FormatterToken> argList) {
return argList;
}

FormatterToken token = argList.get(0);
FormatterToken token = argList.getFirst();
if (token.getType() == TokenType.SPACE) {
argList.remove(0);
argList.removeFirst();
if (argList.isEmpty()) {
return argList;
}
}

token = argList.get(argList.size() - 1);
token = argList.getLast();
if (token.getType() == TokenType.SPACE) {
argList.remove(argList.size() - 1);
argList.removeLast();
if (argList.isEmpty()) {
return argList;
}
Expand Down Expand Up @@ -161,9 +161,9 @@ private List<FormatterToken> format(final List<FormatterToken> argList) {
indent++;
index += insertReturnAndIndent(argList, index + 1, indent);
} else if (tokenString.equals(")") && !bracketIndent.isEmpty() && !functionBracket.isEmpty()) {
indent = bracketIndent.remove(bracketIndent.size() - 1);
indent = bracketIndent.removeLast();
index += insertReturnAndIndent(argList, index, indent);
functionBracket.remove(functionBracket.size() - 1);
functionBracket.removeLast();
} else if (tokenString.equals(",")) {
index += insertReturnAndIndent(argList, index + 1, indent);
} else if (statementDelimiters.contains(tokenString)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,18 @@ public enum GradleVersionSupport {
final String version;

GradleVersionSupport(String version) {
String minVersionForRunningJRE;
switch (Jvm.version()) {
String minVersionForRunningJRE = switch (Jvm.version()) {
case 25:
// TODO: https://docs.gradle.org/current/userguide/compatibility.html
case 24:
minVersionForRunningJRE = "8.14";
break;
case 23:
minVersionForRunningJRE = "8.10";
break;
case 22:
minVersionForRunningJRE = "8.8";
break;
case 21:
minVersionForRunningJRE = "8.5";
break;
case 20:
minVersionForRunningJRE = "8.3";
break;
case 19:
minVersionForRunningJRE = "7.6";
break;
case 18:
minVersionForRunningJRE = "7.5";
break;
default:
minVersionForRunningJRE = null;
break;
}
case 24: yield "8.14";
case 23: yield "8.10";
case 22: yield "8.8";
case 21: yield "8.5";
case 20: yield "8.3";
case 19: yield "7.6";
case 18: yield "7.5";
default: yield null;
};
if (minVersionForRunningJRE != null && GradleVersion.version(minVersionForRunningJRE).compareTo(GradleVersion.version(version)) > 0) {
this.version = minVersionForRunningJRE;
} else {
Expand Down
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 @@ -70,7 +70,7 @@ private void runWith(boolean configurationCache, String... arguments) throws IOE
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
try (Writer outputWriter = new StringPrinter(output::append).toWriter();
Writer errorWriter = new StringPrinter(error::append).toWriter();) {
Writer errorWriter = new StringPrinter(error::append).toWriter()) {
gradleRunner(configurationCache)
.withArguments(arguments)
.forwardStdOutput(outputWriter)
Expand Down
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 @@ -176,15 +176,11 @@ void useJavaCommunityPlugin(String prettierVersion) throws IOException {
@ParameterizedTest(name = "{index}: useJavaCommunityPluginFileConfig with prettier {0}")
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
void useJavaCommunityPluginFileConfig(String prettierVersion) throws IOException {
var prettierPluginJava = "";
switch (prettierVersion) {
case PRETTIER_VERSION_2:
prettierPluginJava = "2.1.0"; // last version to support v2
break;
case PRETTIER_VERSION_3:
prettierPluginJava = "2.3.0"; // latest to support v3
break;
}
var prettierPluginJava = switch (prettierVersion) {
case PRETTIER_VERSION_2 -> "2.1.0";
case PRETTIER_VERSION_3 -> "2.3.0";
default -> "";
};
setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc_java_plugin.yml");
setFile("build.gradle").toLines(
"plugins {",
Expand Down
Loading
Loading