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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
cancel-in-progress: true
jobs:
sanity-check:
name: SanityCheck
name: Sanity Check 🦢️
runs-on: ubuntu-latest
env:
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
Expand All @@ -27,13 +27,13 @@ jobs:
with:
distribution: "temurin"
java-version: 21
- name: gradle caching
- name: Gradle setup 🐘
uses: gradle/actions/setup-gradle@v5
- name: spotlessCheck
- name: Spotless ✨
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this alignment of naming and convention something we want to consider, please?

run: ./gradlew spotlessCheck
- name: rewriteDryRun
- name: Rewrite 🦉
run: ./gradlew rewriteDryRun
- name: assemble testClasses
- name: Assemble Test Classes 📦
run: ./gradlew assemble testClasses
build:
needs: sanity-check
Expand Down
11 changes: 6 additions & 5 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'org.openrewrite.rewrite'
rewrite {
activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck')
configFile = project.getRootProject().file("${rootDir}/gradle/rewrite.yml")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also follow project convent, thus move away from root not to bother around.

same here.

kind of takes away the focus.

exclusions.addAll(
'**.dirty.java',
'**FormatterProperties.java',
Expand All @@ -21,9 +22,9 @@ rewrite {
failOnDryRunResults = true
}
dependencies {
rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.22.0')
rewrite('org.openrewrite.recipe:rewrite-java-security:3.22.0')
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.16.0')
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.22.0')
rewrite('org.openrewrite.recipe:rewrite-third-party:0.31.2')
rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.24.0')
rewrite('org.openrewrite.recipe:rewrite-java-security:3.24.0')
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.17.0')
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.24.0')
rewrite('org.openrewrite.recipe:rewrite-third-party:0.32.1')
}
7 changes: 0 additions & 7 deletions rewrite.yml → gradle/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ type: specs.openrewrite.org/v1beta/recipe
name: com.diffplug.spotless.openrewrite.SanityCheck
displayName: Apply all Java & Gradle best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
tags:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just c&p from checkstyle approach. Imho this is not mandatory and kind of takes away the focus.

- java
- gradle
- static-analysis
- cleanup
recipeList:
- org.openrewrite.gradle.EnableGradleBuildCache
- org.openrewrite.gradle.EnableGradleParallelExecution
Expand Down Expand Up @@ -39,7 +34,6 @@ recipeList:
- org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
- org.openrewrite.staticanalysis.RemoveUnusedPrivateFields
- org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
- org.openrewrite.staticanalysis.ReplaceApacheCommonsLang3ValidateNotNullWithObjectsRequireNonNull
- org.openrewrite.staticanalysis.SimplifyTernaryRecipes
- org.openrewrite.staticanalysis.URLEqualsHashCodeRecipes
- org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources
Expand All @@ -64,5 +58,4 @@ recipeList:
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
- tech.picnic.errorprone.refasterrules.StringRulesRecipes
- tech.picnic.errorprone.refasterrules.TimeRulesRecipes
# - org.openrewrite.java.migrate.lang.FindVirtualThreadOpportunities # don't want to use: https://github.com/diffplug/spotless/pull/2684#discussion_r2433831887
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here.

kind of takes away the focus.

---
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
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
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();
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
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 @@ -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
Loading