Skip to content
Draft
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: 4 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck')
activeStyle('com.diffplug.spotless.openrewrite.SpotlessFormat')
exclusions.addAll(
'**.dirty.java',
'**DiffMessageFormatterTest.java',
'**EclipseJdtSortMembers.java',
'**FormatterProperties.java',
'**PaddedCellTaskTest.java',
'**_gradle_node_plugin_example_**',
'**gradle/changelog.gradle',
'**gradle/java-publish.gradle',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 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 @@ -53,7 +53,7 @@ static class FormatterCallback implements Function2<LintError, Boolean, Unit> {
}

@Override
public Unit invoke(LintError lintError, Boolean corrected) {
public @Nullable Unit invoke(LintError lintError, Boolean corrected) {
if (!corrected) {
errors.add(lintError);
}
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 @@ -120,12 +120,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() {
public @Nullable V getRecommendedFormatterVersion() {
Integer configuredJvmVersionOrNull = jvm2fmtMaxVersion.floorKey(Jvm.version());
return configuredJvmVersionOrNull == null ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
}

@Nullable public V getMinimumRequiredFormatterVersion() {
public @Nullable V getMinimumRequiredFormatterVersion() {
Integer configuredJvmVersionOrNull = jvm2fmtMinVersion.floorKey(Jvm.version());
return configuredJvmVersionOrNull == null ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
}
Expand Down
6 changes: 3 additions & 3 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 @@ -105,12 +105,12 @@ private static PaddedCell check(Formatter formatter, File file, String original,
}
String appliedOnce = formatter.computeWithLint(original, file, exceptionPerStep);
if (appliedOnce.equals(original)) {
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
return Type.CONVERGE.create(file, List.of(appliedOnce));
}

String appliedTwice = formatter.computeWithLint(appliedOnce, file, exceptionPerStep);
if (appliedOnce.equals(appliedTwice)) {
return Type.CONVERGE.create(file, Collections.singletonList(appliedOnce));
return Type.CONVERGE.create(file, List.of(appliedOnce));
}

List<String> appliedN = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/ValuePerStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ValuePerStep<T> extends AbstractList<T> {
}

@Override
public T get(int index) {
public @Nullable T get(int index) {
if (multipleValues != null) {
return (T) multipleValues[index];
} else if (valueIdx == index) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -299,7 +299,7 @@ private State createState() throws IOException, InterruptedException {
validateBiomeExecutable(resolvedPathToExe);
validateBiomeConfigPath(configPath, version);
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe)));
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
makeExecutable(resolvedPathToExe);
return new State(resolvedPathToExe, exeSignature, configPath, language);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
return new EslintConfig(eslintConfigPath, this.eslintConfigJs);
}

@Nullable public File getEslintConfigPath() {
public @Nullable File getEslintConfigPath() {
return eslintConfigPathSignature == null ? null : eslintConfigPathSignature.get().getOnlyFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -65,7 +64,7 @@ public static Map<String, String> defaultDevDependencies() {
}

public static Map<String, String> defaultDevDependenciesWithEslint(String version) {
return Collections.singletonMap("eslint", version);
return Map.of("eslint", version);
}

public static FormatterStep create(Map<String, String> devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) {
return new EslintTypescriptConfig(eslintConfigPath, this.getEslintConfigJs(), getTypescriptConfigPath());
}

@Nullable public File getTypescriptConfigPath() {
public @Nullable File getTypescriptConfigPath() {
return typescriptConfigPathSignature == null ? null : this.typescriptConfigPathSignature.get().getOnlyFile();
}
}
5 changes: 2 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java
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 All @@ -21,7 +21,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -45,7 +44,7 @@ JsonWriter putAll(Map<String, ?> values) {
}

JsonWriter put(String name, Object value) {
verifyValues(Collections.singletonMap(name, value));
verifyValues(Map.of(name, value));
this.valueMap.put(name, value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.Serial;
import java.io.Serializable;
import java.time.Duration;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -164,7 +163,7 @@ protected static String replaceDevDependencies(String template, Map<String, Stri
builder.append(",\n");
}
}
return replacePlaceholders(template, Collections.singletonMap("devDependencies", builder.toString()));
return replacePlaceholders(template, Map.of("devDependencies", builder.toString()));
}

private static String replacePlaceholders(String template, Map<String, String> replacements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PrettierConfig(@Nullable File prettierConfigPath, @Nullable Map<String, O
this.options = options == null ? new TreeMap<>() : new TreeMap<>(options);
}

@Nullable public File getPrettierConfigPath() {
public @Nullable File getPrettierConfigPath() {
return prettierConfigPathSignature == null ? null : prettierConfigPathSignature.get().getOnlyFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -48,7 +47,7 @@ public static Map<String, String> defaultDevDependencies() {
}

public static Map<String, String> defaultDevDependenciesWithPrettier(String version) {
return Collections.singletonMap("prettier", version);
return Map.of("prettier", version);
}

public static FormatterStep create(Map<String, String> devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -196,7 +198,7 @@ public DynamicErrorInvocationHandler(File file) {
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String message = (String) args[0];
long line = (long) args[1];
long col = (long) args[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.Set;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -87,7 +88,7 @@ private static final class State implements Serializable {

State(JarState jarState, @Nullable File configFile) throws IOException {
this.jarState = jarState;
this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile));
this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Set.of(configFile));
}

FormatterFunc createFormat() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public String getName() {
return "hack to force serializing objects to byte array";
}

@Nullable @Override
public String format(String rawUnix, File file) throws Exception {
@Override
public @Nullable String format(String rawUnix, File file) throws Exception {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void itCalculatesSameNodeModulesDirForSameContent() throws IOException {
@Test
void itCalculatesDifferentNodeModulesDirForDifferentPackageJson() throws IOException {
File testDir = newFolder("build");
String packageJsonContent1 = prettierPackageJson(Collections.singletonMap("prettier-plugin-xy", "^2.0.0"));
String packageJsonContent2 = prettierPackageJson(Collections.singletonMap("prettier-plugin-xy", "^2.1.0"));
String packageJsonContent1 = prettierPackageJson(Map.of("prettier-plugin-xy", "^2.0.0"));
String packageJsonContent2 = prettierPackageJson(Map.of("prettier-plugin-xy", "^2.1.0"));
String serveJsContent = "fun main() { console.log('Hello, world!'); }";

NodeServerLayout layout1 = new NodeServerLayout(testDir, packageJsonContent1, serveJsContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.Map;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.json.JacksonConfig;
Expand All @@ -36,7 +36,7 @@ protected AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension form
}

public T feature(String feature, boolean toggle) {
this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -200,7 +199,7 @@ protected FormatterStep createStep() {

private void fixParserToJavascript() {
if (this.prettierConfig == null) {
this.prettierConfig = Collections.singletonMap("parser", DEFAULT_PRETTIER_JS_PARSER);
this.prettierConfig = Map.of("parser", DEFAULT_PRETTIER_JS_PARSER);
} else {
final Object currentParser = this.prettierConfig.get("parser");
if (PRETTIER_JS_PARSERS.contains(String.valueOf(currentParser))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -165,7 +164,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) {
* Refers to com.fasterxml.jackson.core.JsonGenerator.Feature
*/
public JacksonJsonGradleConfig jsonFeature(String feature, boolean toggle) {
this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendJsonFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected FormatterStep createStep() {

private void fixParserToTypescript() {
if (this.prettierConfig == null) {
this.prettierConfig = new TreeMap<>(Collections.singletonMap("parser", "typescript"));
this.prettierConfig = new TreeMap<>(Map.of("parser", "typescript"));
} else {
final Object replaced = this.prettierConfig.put("parser", "typescript");
if (replaced != null) {
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 All @@ -15,7 +15,7 @@
*/
package com.diffplug.gradle.spotless;

import java.util.Collections;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -62,7 +62,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) {
* Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature
*/
public JacksonYamlGradleConfig yamlFeature(String feature, boolean toggle) {
this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle));
this.jacksonConfig.appendYamlFeatureToToggle(Map.of(feature, toggle));
formatExtension.replaceStep(createStep());
return this;
}
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 All @@ -16,8 +16,8 @@
package com.diffplug.gradle.spotless;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.gradle.api.Project;
import org.gradle.api.services.BuildServiceParameters;
Expand Down Expand Up @@ -50,7 +50,7 @@ void testLineEndings() throws Exception {
File testFile = setFile("testFile").toContent("\r\n");
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");

spotlessTask.setTarget(Collections.singleton(testFile));
spotlessTask.setTarget(Set.of(testFile));
Tasks.execute(spotlessTask);

assertFile(outputFile).hasContent("\n");
Expand All @@ -60,7 +60,7 @@ void testLineEndings() throws Exception {
void testStep() throws Exception {
File testFile = setFile("testFile").toContent("apple");
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");
spotlessTask.setTarget(Collections.singleton(testFile));
spotlessTask.setTarget(Set.of(testFile));

spotlessTask.setSteps(List.of(ReplaceStep.create("double-p", "pp", "p")));
Tasks.execute(spotlessTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Base64;
import java.util.Objects;

import javax.annotation.Nullable;

import org.codehaus.plexus.resource.ResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
Expand All @@ -52,7 +54,7 @@ public FileLocator(ResourceManager resourceManager, File baseDir, File buildDir)
* If the given path is a local file returns it as such unchanged, otherwise
* extracts the given resource to a randomly-named file in the build folder.
*/
public File locateFile(String path) {
public @Nullable File locateFile(String path) {
if (isNullOrEmpty(path)) {
return null;
}
Expand Down
Loading
Loading