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
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ artifactIdMaven=spotless-maven-plugin
artifactIdGradle=spotless-plugin-gradle

# Build requirements
# bump 21 after: https://github.com/gradle/gradle/issues/35768
VER_JAVA=17
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.

gradle needs 17. We would break the plugin release not compiling.

VER_JSR_305=3.0.2

# Dependencies provided by Spotless plugin
VER_SLF4J=[1.6,2.0[
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.

is this intended?

VER_SLF4J=[1.6,2.0]

# Used in multiple places
VER_DURIAN=1.2.0
Expand Down
63 changes: 31 additions & 32 deletions gradle/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,48 @@ apply plugin: 'net.ltgt.errorprone'

dependencies {
errorprone('com.google.errorprone:error_prone_core:2.42.0')
errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.26.0')
// errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.26.0') // bug: https://github.com/google/error-prone/issues/5365
}

tasks.withType(JavaCompile).configureEach {
options.errorprone {
disableAllWarnings = true // https://github.com/diffplug/spotless/issues/2745
disable( // consider fix, or reasoning.
'FunctionalInterfaceMethodChanged',
'JavaxInjectOnAbstractMethod',
'OverridesJavaxInjectableMethod',
)
error(
'AmbiguousJsonCreator',
'AssertJNullnessAssertion',
'AutowiredConstructor',
'CanonicalAnnotationSyntax',
'CollectorMutability',
'ConstantNaming',
'DirectReturn',
'EmptyMethod',
'ExplicitArgumentEnumeration',
'ExplicitEnumOrdering',
'IdentityConversion',
'ImmutablesSortedSetComparator',
'IsInstanceLambdaUsage',
'MockitoMockClassReference',
'MockitoStubbing',
'NestedOptionals',
'PrimitiveComparison',
'RedundantStringConversion',
'RedundantStringEscape',
'ReturnValueIgnored',
'SelfAssignment',
'StringJoin',
'StringJoining',
'UnnecessarilyFullyQualified',
'UnnecessaryLambda',
)
// error(
// 'AmbiguousJsonCreator',
// 'AssertJNullnessAssertion',
// 'AutowiredConstructor',
// 'CanonicalAnnotationSyntax',
// 'CollectorMutability',
// 'ConstantNaming',
// 'DirectReturn',
// 'EmptyMethod',
// 'ExplicitArgumentEnumeration',
// 'ExplicitEnumOrdering',
// 'IdentityConversion',
// 'ImmutablesSortedSetComparator',
// 'IsInstanceLambdaUsage',
// 'MockitoMockClassReference',
// 'MockitoStubbing',
// 'NestedOptionals',
// 'PrimitiveComparison',
// 'RedundantStringConversion',
// 'RedundantStringEscape',
// 'ReturnValueIgnored',
// 'SelfAssignment',
// 'StringJoin',
// 'StringJoining',
// 'UnnecessarilyFullyQualified',
// 'UnnecessaryLambda',
// )
// bug: this only happens when the file is dirty.
// might be an up2date (caching) issue, as file is currently in corrupt state.
// ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
errorproneArgs.add('-XepExcludedPaths:' +
'.*/SelfTest.java|' +
'.*/GradleIntegrationHarness.java'
)
// excludedPaths.add('.*/SelfTest.java');
// excludedPaths.add('.*/GradleIntegrationHarness.java');
}
}
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());
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.

/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java:320: error: cannot find symbol
			method.invoke(builder, selectedEnumValueList.getFirst());
			                                            ^
  symbol:   method getFirst()
  location: variable selectedEnumValueList of type List<?>
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java:458: error: cannot find symbol
		Method method = methods.getFirst();
		                       ^
  symbol:   method getFirst()
  location: variable methods of type List<Method>

whats the deal?

Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getFirst() is a method introduced in Java 21, IIRC, and we still support versions as old as Java 17.

Therefore, what you're probably seeing is that it fails to compile on Java 17, so this change won't work, sadly.

}
for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); i++) {
addIntendedLine(DIFF_INDENT, lines.get(i));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/PaddedCell.java
Original file line number Diff line number Diff line change
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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to my other comment, getLast() was introduced in Java 21, IIRC, so I doubt this change will work, I'm afraid.

In fact, I'm sure most if not all of the changes from this OpenRewrite rule won't work for us, precisely because we need to maintain support for Java 17.

case CYCLE: return Collections.min(steps, Comparator.comparingInt(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 @@ -456,32 +456,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
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() && ImportSorter.N.equals(template.get(template.size() - 1))) {
template.remove(template.size() - 1);
if (!template.isEmpty() && ImportSorter.N.equals(template.getLast())) {
template.removeLast();
}
return template;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/npm/TimedLogger.java
Original file line number Diff line number Diff line change
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 @@ -317,7 +317,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 @@ -455,7 +455,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
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 (")".equals(tokenString) && !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 (",".equals(tokenString)) {
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 @@ -29,7 +29,7 @@ public class SpotlessPlugin implements Plugin<Project> {
static final String SPOTLESS_MODERN = "spotlessModern";
static final String VER_GRADLE_MIN = "8.1";
static final String VER_GRADLE_MIN_VERSION_FOR_CUSTOM = "8.4";
private static final int MINIMUM_JRE = 17;
private static final int MINIMUM_JRE = 21;

@Override
public void apply(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected void process(String name, Iterable<File> files, Formatter formatter, U
.getMessage());
} else if (!lintProblems.isEmpty()) {
// Show lints only if there are no formatting violations
Map.Entry<File, LintState> firstLintProblem = lintProblems.get(0);
Map.Entry<File, LintState> firstLintProblem = lintProblems.getFirst();
File file = firstLintProblem.getKey();
LintState lintState = firstLintProblem.getValue();
String stepName = lintState.getLintsByStep(formatter).keySet().iterator().next();
Expand Down
2 changes: 1 addition & 1 deletion rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ recipeList:
- org.openrewrite.java.format.NormalizeFormat
- org.openrewrite.java.format.NormalizeLineBreaks
- org.openrewrite.java.format.RemoveTrailingWhitespace
- org.openrewrite.java.migrate.UpgradeToJava17
- org.openrewrite.java.migrate.UpgradeToJava21
- org.openrewrite.java.migrate.lang.StringRulesRecipes
- org.openrewrite.java.migrate.util.JavaLangAPIs
- org.openrewrite.java.migrate.util.JavaUtilAPIs
Expand Down
14 changes: 6 additions & 8 deletions testlib/src/test/java/com/diffplug/spotless/PaddedCellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ void pingPong() throws IOException {

@Test
void fourState() throws IOException {
misbehaved(input -> {
misbehaved(input ->
// @formatter:off
switch (input) {
case "A": return "B";
case "B": return "C";
case "C": return "D";
default: return "A";
}
// @formatter:on
}, "CCC", CYCLE, "A,B,C,D", "A");
case "A" -> "B";
case "B" -> "C";
case "C" -> "D";
default -> "A";
}, "CCC", CYCLE, "A,B,C,D", "A");
}

@Test
Expand Down
Loading