diff --git a/CHANGES.md b/CHANGES.md index 5eb084f98b..2cc048e8a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Removed * **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945)) * **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954)) +* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119)) ## [2.45.0] - 2024-01-23 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java similarity index 90% rename from lib/src/main/java/com/diffplug/spotless/rome/Architecture.java rename to lib/src/main/java/com/diffplug/spotless/biome/Architecture.java index 9ceaeb8632..29511842e2 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/Architecture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; /** * Enumeration of possible computer architectures. @@ -34,11 +34,11 @@ public static Architecture guess() { var version = System.getProperty("os.version"); if (arch == null || arch.isBlank()) { - throw new IllegalStateException("No OS information is available, specify the Rome executable manually"); + throw new IllegalStateException("No OS information is available, specify the Biome executable manually"); } var msg = "Unsupported architecture " + arch + "/" + version - + ", specify the path to the Rome executable manually"; + + ", specify the path to the Biome executable manually"; if (arch.equals("ppc64le")) { throw new IllegalStateException(msg); diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/biome/BiomeExecutableDownloader.java similarity index 98% rename from lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java rename to lib/src/main/java/com/diffplug/spotless/biome/BiomeExecutableDownloader.java index 052f72def4..c01d11a20c 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/BiomeExecutableDownloader.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; import java.io.IOException; import java.math.BigInteger; @@ -41,8 +41,8 @@ * Downloader for the Biome executable: * https://github.com/biomejs/biome. */ -final class RomeExecutableDownloader { - private static final Logger logger = LoggerFactory.getLogger(RomeExecutableDownloader.class); +final class BiomeExecutableDownloader { + private static final Logger logger = LoggerFactory.getLogger(BiomeExecutableDownloader.class); /** * The checksum algorithm to use for checking the integrity of downloaded files. @@ -80,7 +80,7 @@ final class RomeExecutableDownloader { * @param flavor Flavor of Biome to use. * @param downloadDir Directory where to store the downloaded executable. */ - public RomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) { + public BiomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) { this.flavor = flavor; this.downloadDir = downloadDir; } diff --git a/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/biome/BiomeFlavor.java similarity index 87% rename from lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java rename to lib/src/main/java/com/diffplug/spotless/biome/BiomeFlavor.java index dbfd43eee9..bcb065edea 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/BiomeFlavor.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; /** * The flavor of Biome to use. Exists for compatibility reason, may be removed @@ -24,17 +24,7 @@ public enum BiomeFlavor { /** The new forked Biome project. */ BIOME("biome", "1.2.0", "biome.json", "biome-%s-%s-%s", - "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s"), - - /** - * The old deprecated Rome project. - * - * @deprecated Will be removed once the old Rome project is not supported - * anymore. - */ - @Deprecated - ROME("rome", "12.0.0", "rome.json", "rome-%s-%s-%s", - "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s"); + "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s"); private final String configName; private final String defaultVersion; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java similarity index 95% rename from lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java rename to lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java index de5b3e80ee..2db9e8cb2a 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; import java.io.File; import java.io.IOException; @@ -40,11 +40,11 @@ /** * formatter step that formats JavaScript and TypeScript code with Biome: * https://github.com/biomejs/biome. - * It delegates to the Biome executable. The Rome executable is downloaded from + * It delegates to the Biome executable. The Biome executable is downloaded from * the network when no executable path is provided explicitly. */ -public class RomeStep { - private static final Logger logger = LoggerFactory.getLogger(RomeStep.class); +public class BiomeStep { + private static final Logger logger = LoggerFactory.getLogger(BiomeStep.class); /** * Path to the directory with the {@code biome.json} config file, can be @@ -113,8 +113,8 @@ public String name() { * @param downloadDir Directory where to place the downloaded executable. * @return A new Biome step that download the executable from the network. */ - public static RomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) { - return new RomeStep(flavor, version, null, downloadDir); + public static BiomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) { + return new BiomeStep(flavor, version, null, downloadDir); } /** @@ -125,8 +125,8 @@ public static RomeStep withExeDownload(BiomeFlavor flavor, String version, Strin * @param pathToExe Path to the Biome executable to use. * @return A new Biome step that format with the given executable. */ - public static RomeStep withExePath(BiomeFlavor flavor, String pathToExe) { - return new RomeStep(flavor, null, pathToExe, null); + public static BiomeStep withExePath(BiomeFlavor flavor, String pathToExe) { + return new BiomeStep(flavor, null, pathToExe, null); } /** @@ -230,7 +230,7 @@ private static void validateBiomeExecutable(String resolvedPathToExe) { * @param pathToExe Path to the Biome executable to use. * @param downloadDir Directory where to place the downloaded executable. */ - private RomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) { + private BiomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) { this.flavor = flavor; this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor); this.pathToExe = pathToExe; @@ -255,7 +255,7 @@ public FormatterStep create() { * a file named {@code biome.json}. * @return This builder instance for chaining method calls. */ - public RomeStep withConfigPath(String configPath) { + public BiomeStep withConfigPath(String configPath) { this.configPath = configPath; return this; } @@ -280,7 +280,7 @@ public RomeStep withConfigPath(String configPath) { * @param language The language of the files to format. * @return This builder instance for chaining method calls. */ - public RomeStep withLanguage(String language) { + public BiomeStep withLanguage(String language) { this.language = language; return this; } @@ -333,7 +333,7 @@ private String resolveExe() throws IOException, InterruptedException { return pathToExe; } } else { - var downloader = new RomeExecutableDownloader(flavor, Paths.get(downloadDir)); + var downloader = new BiomeExecutableDownloader(flavor, Paths.get(downloadDir)); var downloaded = downloader.ensureDownloaded(version).toString(); makeExecutable(downloaded); return downloaded; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/OS.java b/lib/src/main/java/com/diffplug/spotless/biome/OS.java similarity index 88% rename from lib/src/main/java/com/diffplug/spotless/rome/OS.java rename to lib/src/main/java/com/diffplug/spotless/biome/OS.java index 44c87d9ece..ab0ba4b8db 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/OS.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/OS.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; import java.util.Locale; @@ -38,12 +38,12 @@ enum OS { public static OS guess() { var osName = System.getProperty("os.name"); if (osName == null || osName.isBlank()) { - throw new IllegalStateException("No OS information is available, specify the Rome executable manually"); + throw new IllegalStateException("No OS information is available, specify the Biome executable manually"); } var osNameUpper = osName.toUpperCase(Locale.ROOT); if (osNameUpper.contains("SUNOS") || osName.contains("AIX")) { throw new IllegalStateException( - "Unsupported OS " + osName + ", specify the path to the Rome executable manually"); + "Unsupported OS " + osName + ", specify the path to the Biome executable manually"); } if (osNameUpper.contains("WINDOWS")) { return OS.WINDOWS; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java b/lib/src/main/java/com/diffplug/spotless/biome/Platform.java similarity index 97% rename from lib/src/main/java/com/diffplug/spotless/rome/Platform.java rename to lib/src/main/java/com/diffplug/spotless/biome/Platform.java index c50608830a..590e303d98 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.rome; +package com.diffplug.spotless.biome; /** * Represents a platform where code is run, consisting of an operating system diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index acbe0231f9..27ec728993 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -20,6 +20,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057)) * Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078)) * Bump default `sortpom` version to latest `3.4.1` -> `4.0.0` and support versions back to `3.2.1`. ([#2115](https://github.com/diffplug/spotless/pull/2115)) +### Removed +* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119)) ## [6.25.0] - 2024-01-23 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 4542c69763..819ff3d42a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1299,12 +1299,6 @@ a formatter that for the frontend written in Rust, which has a native binary, do is pretty fast. It can currently format JavaScript, TypeScript, JSX, and JSON, and may support [more frontend languages](https://biomejs.dev/internals/language-support/) such as CSS in the future. -Note: Biome [was formerly called Rome](https://biomejs.dev/blog/annoucing-biome/). Configurations with -the old `` tag and `rome(...)` function are still supported for the time being. This will be removed -in a future version, you should migrate to the new `` tag or `biome(...)` function. The configuration -remains the same, you only need to update the version. If you are using a custom `rome.json` configuration file, -you need to rename it to `biome.json`. - You can use Biome in any language-specific format for supported languages, but usually you will be creating a generic format. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BiomeStepConfig.java similarity index 95% rename from plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java rename to plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BiomeStepConfig.java index 98c4000a8b..d66048a7b0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BiomeStepConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,10 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.rome.BiomeFlavor; -import com.diffplug.spotless.rome.RomeStep; +import com.diffplug.spotless.biome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeStep; -public abstract class RomeStepConfig> { +public abstract class BiomeStepConfig> { /** * Optional path to the directory with configuration file for Biome. The file * must be named {@code biome.json}. When none is given, the default @@ -95,7 +95,7 @@ public abstract class RomeStepConfig> { @Nullable private String version; - protected RomeStepConfig(Project project, Consumer replaceStep, BiomeFlavor flavor, + protected BiomeStepConfig(Project project, Consumer replaceStep, BiomeFlavor flavor, String version) { this.project = requireNonNull(project); this.replaceStep = requireNonNull(replaceStep); @@ -234,13 +234,13 @@ private File findDataDir() { * * @return A builder for a Biome step. */ - private RomeStep newBuilder() { + private BiomeStep newBuilder() { if (pathToExe != null) { var resolvedPathToExe = resolvePathToExe(); - return RomeStep.withExePath(flavor, resolvedPathToExe); + return BiomeStep.withExePath(flavor, resolvedPathToExe); } else { var downloadDir = resolveDownloadDir(); - return RomeStep.withExeDownload(flavor, version, downloadDir); + return BiomeStep.withExeDownload(flavor, version, downloadDir); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 08d6088d60..94e5298b66 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -53,6 +53,7 @@ import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.biome.BiomeFlavor; import com.diffplug.spotless.cpp.ClangFormatStep; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; @@ -67,7 +68,6 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.BiomeFlavor; import groovy.lang.Closure; @@ -728,15 +728,15 @@ protected FormatterStep createStep() { * the file name. It should be specified as a formatter step for a generic * format{ ... }. */ - public class BiomeGeneric extends RomeStepConfig { + public class BiomeGeneric extends BiomeStepConfig { @Nullable String language; /** - * Creates a new Rome config that downloads the Rome executable for the given + * Creates a new Biome config that downloads the Biome executable for the given * version from the network. * - * @param version Rome version to use. The default version is used when + * @param version Biome version to use. The default version is used when * null. */ public BiomeGeneric(String version) { @@ -779,65 +779,6 @@ protected BiomeGeneric getThis() { } } - /** - * Generic Rome formatter step that detects the language of the input file from - * the file name. It should be specified as a formatter step for a generic - * format{ ... }. - * - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ - @Deprecated - public class RomeGeneric extends RomeStepConfig { - @Nullable - String language; - - /** - * Creates a new Rome config that downloads the Rome executable for the given - * version from the network. - * - * @param version Rome version to use. The default version is used when - * null. - */ - public RomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, BiomeFlavor.ROME, version); - } - - /** - * Sets the language (syntax) of the input files to format. When - * null or the empty string, the language is detected automatically - * from the file name. Currently the following languages are supported by Rome: - *
    - *
  • js (JavaScript)
  • - *
  • jsx (JavaScript + JSX)
  • - *
  • js? (JavaScript or JavaScript + JSX, depending on the file - * extension)
  • - *
  • ts (TypeScript)
  • - *
  • tsx (TypeScript + JSX)
  • - *
  • ts? (TypeScript or TypeScript + JSX, depending on the file - * extension)
  • - *
  • json (JSON)
  • - *
- * - * @param language The language of the files to format. - * @return This step for further configuration. - */ - public RomeGeneric language(String language) { - this.language = language; - replaceStep(); - return this; - } - - @Override - protected String getLanguage() { - return language; - } - - @Override - protected RomeGeneric getThis() { - return this; - } - } - /** Uses the default version of prettier. */ public PrettierConfig prettier() { return prettier(PrettierFormatterStep.defaultDevDependencies()); @@ -860,41 +801,17 @@ public PrettierConfig prettier(Map devDependencies) { * offline, you can specify the path to the Biome executable via * {@code biome().pathToExe(...)}. */ - public RomeStepConfig biome() { + public BiomeStepConfig biome() { return biome(null); } /** Downloads the given Biome version from the network. */ - public RomeStepConfig biome(String version) { + public BiomeStepConfig biome(String version) { var biomeConfig = new BiomeGeneric(version); addStep(biomeConfig.createStep()); return biomeConfig; } - /** - * Defaults to downloading the default Rome version from the network. To work - * offline, you can specify the path to the Rome executable via - * {@code rome().pathToExe(...)}. - * - * @deprecated Use {@link #biome(String)}. - */ - @Deprecated - public RomeStepConfig rome() { - return rome(null); - } - - /** - * Downloads the given Rome version from the network. - * - * @deprecated Use {@link #biome(String)}. - */ - @Deprecated - public RomeStepConfig rome(String version) { - var romeConfig = new RomeGeneric(version); - addStep(romeConfig.createStep()); - return romeConfig; - } - /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { return clangFormat(ClangFormatStep.defaultVersion()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index b14bd29ab8..5532045bc2 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,11 +30,11 @@ import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.biome.BiomeFlavor; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.BiomeFlavor; public class JavascriptExtension extends FormatExtension { @@ -154,30 +154,6 @@ public BiomeJs biome(String version) { return biomeConfig; } - /** - * Defaults to downloading the default Rome version from the network. To work - * offline, you can specify the path to the Rome executable via - * {@code rome().pathToExe(...)}. - * - * @deprecated Use {@link #biome()}. - */ - @Deprecated - public RomeJs rome() { - return rome(null); - } - - /** - * Downloads the given Rome version from the network. - * - * @deprecated Use {@link #biome(String)}. - */ - @Deprecated - public RomeJs rome(String version) { - var romeConfig = new RomeJs(version); - addStep(romeConfig.createStep()); - return romeConfig; - } - private static final String DEFAULT_PRETTIER_JS_PARSER = "babel"; private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow"); @@ -185,7 +161,7 @@ public RomeJs rome(String version) { /** * Biome formatter step for JavaScript. */ - public class BiomeJs extends RomeStepConfig { + public class BiomeJs extends BiomeStepConfig { /** * Creates a new Biome formatter step config for formatting JavaScript files. * Unless overwritten, the given Biome version is downloaded from the network. @@ -207,34 +183,6 @@ protected BiomeJs getThis() { } } - /** - * Rome formatter step for JavaScript. - * - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ - @Deprecated - public class RomeJs extends RomeStepConfig { - /** - * Creates a new Rome formatter step config for formatting JavaScript files. - * Unless overwritten, the given Rome version is downloaded from the network. - * - * @param version Rome version to use. - */ - public RomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, BiomeFlavor.ROME, version); - } - - @Override - protected String getLanguage() { - return "js?"; - } - - @Override - protected RomeJs getThis() { - return this; - } - } - /** * Overrides the parser to be set to a js parser. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 441e25b93d..80e207d6da 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,12 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.biome.BiomeFlavor; import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonPatchStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; -import com.diffplug.spotless.rome.BiomeFlavor; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; @@ -76,30 +76,6 @@ public BiomeJson biome(String version) { return biomeConfig; } - /** - * Defaults to downloading the default Rome version from the network. To work - * offline, you can specify the path to the Rome executable via - * {@code rome().pathToExe(...)}. - * - * @deprecated Use {@link #biome()}. - */ - @Deprecated - public RomeJson rome() { - return rome(null); - } - - /** - * Downloads the given Rome version from the network. - * - * @deprecated Use {@link #biome(String)}. - */ - @Deprecated - public RomeJson rome(String version) { - var romeConfig = new RomeJson(version); - addStep(romeConfig.createStep()); - return romeConfig; - } - public JsonPatchConfig jsonPatch(List> patch) { return new JsonPatchConfig(patch); } @@ -209,7 +185,7 @@ protected final FormatterStep createStep() { /** * Biome formatter step for JSON. */ - public class BiomeJson extends RomeStepConfig { + public class BiomeJson extends BiomeStepConfig { /** * Creates a new Biome formatter step config for formatting JSON files. Unless * overwritten, the given Biome version is downloaded from the network. @@ -231,34 +207,6 @@ protected BiomeJson getThis() { } } - /** - * Rome formatter step for JSON. - * - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ - @Deprecated - public class RomeJson extends RomeStepConfig { - /** - * Creates a new Rome formatter step config for formatting JSON files. Unless - * overwritten, the given Rome version is downloaded from the network. - * - * @param version Rome version to use. - */ - public RomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, BiomeFlavor.ROME, version); - } - - @Override - protected String getLanguage() { - return "json"; - } - - @Override - protected RomeJson getThis() { - return this; - } - } - public class JsonPatchConfig { private String zjsonPatchVersion; private List> patch; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 190a2f8e20..39e050d51e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import com.diffplug.gradle.spotless.JavascriptExtension.EslintBaseConfig; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.biome.BiomeFlavor; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintTypescriptConfig; @@ -38,7 +39,6 @@ import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; -import com.diffplug.spotless.rome.BiomeFlavor; public class TypescriptExtension extends FormatExtension { @@ -243,34 +243,10 @@ public BiomeTs biome(String version) { return biomeConfig; } - /** - * Defaults to downloading the default Rome version from the network. To work - * offline, you can specify the path to the Rome executable via - * {@code rome().pathToExe(...)}. - * - * @deprecated Use {@link #biome()}. - */ - @Deprecated - public RomeTs rome() { - return rome(null); - } - - /** - * Downloads the given Rome version from the network. - * - * @deprecated Use {@link #biome(String)}. - */ - @Deprecated - public RomeTs rome(String version) { - var romeConfig = new RomeTs(version); - addStep(romeConfig.createStep()); - return romeConfig; - } - /** * Biome formatter step for TypeScript. */ - public class BiomeTs extends RomeStepConfig { + public class BiomeTs extends BiomeStepConfig { /** * Creates a new Biome formatter step config for formatting TypeScript files. * Unless overwritten, the given Biome version is downloaded from the network. @@ -292,34 +268,6 @@ protected BiomeTs getThis() { } } - /** - * Rome formatter step for TypeScript. - * - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ - @Deprecated - public class RomeTs extends RomeStepConfig { - /** - * Creates a new Rome formatter step config for formatting TypeScript files. - * Unless overwritten, the given Rome version is downloaded from the network. - * - * @param version Rome version to use. - */ - public RomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, BiomeFlavor.ROME, version); - } - - @Override - protected String getLanguage() { - return "ts?"; - } - - @Override - protected RomeTs getThis() { - return this; - } - } - @Override protected void setupTask(SpotlessTask task) { if (target == null) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java deleted file mode 100644 index e9f33f64ac..0000000000 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright 2023-2024 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.gradle.spotless; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; -import org.owasp.encoder.Encode; - -class RomeIntegrationTest extends GradleIntegrationHarness { - /** - * Tests that rome can be used as a generic formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asGenericStep() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - } - - /** - * Tests that rome can be used as a JavaScript formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asJavaScriptStep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " javascript {", - " target '**/*.js'", - " rome('12.0.0')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - } - - /** - * Tests that rome can be used as a JSON formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asJsonStep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " json {", - " target '**/*.json'", - " rome('12.0.0')", - " }", - "}"); - setFile("rome_test.json").toResource("rome/json/fileBefore.json"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.json").sameAsResource("rome/json/fileAfter.json"); - } - - /** - * Tests that rome can be used as a TypeScript formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asTypeScriptStep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " typescript {", - " target '**/*.ts'", - " rome('12.0.0')", - " }", - "}"); - setFile("rome_test.ts").toResource("rome/ts/fileBefore.ts"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.ts").sameAsResource("rome/ts/fileAfter.ts"); - } - - /** - * Tests that the language can be specified for the generic format step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void canSetLanguageForGenericStep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.nosj'", - " rome('12.0.0').language('json')", - " }", - "}"); - setFile("rome_test.nosj").toResource("rome/json/fileBefore.json"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.nosj").sameAsResource("rome/json/fileAfter.json"); - } - - /** - * Tests that an absolute config path can be specified. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathAbsolute() throws Exception { - var path = newFile("configs").getAbsolutePath(); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').configPath('" + Encode.forJava(path) + "')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); - } - - /** - * Tests that a path to the directory with the rome.json config file can be - * specified. Uses a config file with a line width of 120. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathLineWidth120() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').configPath('configs')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); - } - - /** - * Tests that a path to the directory with the rome.json config file can be - * specified. Uses a config file with a line width of 80. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathLineWidth80() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').configPath('configs')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-80.json"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter80.js"); - } - - /** - * Tests that the download directory can be an absolute path. - * - * @throws Exception When a test failure occurs. - */ - @Test - void downloadDirAbsolute() throws Exception { - var path = newFile("target/bin/rome").getAbsoluteFile().toString(); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').downloadDir('" + Encode.forJava(path) + "')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - assertEquals(2, newFile("target/bin/rome").list().length); - } - - /** - * Tests that the download directory can be changed to a path relative to the - * project's base directory. - * - * @throws Exception When a test failure occurs. - */ - @Test - void downloadDirRelative() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').downloadDir('target/bin/rome')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - assertEquals(2, newFile("target/bin/rome").list().length); - } - - /** - * Tests that the build fails when given Biome executable does not exist. - * - * @throws Exception When a test failure occurs. - */ - @Test - void failureWhenExeNotFound() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').pathToExe('rome/is/missing')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); - assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertThat(spotlessApply.getOutput()).contains("Execution failed for task ':spotlessMyrome'"); - assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist"); - } - - /** - * Tests that the build fails when the input file could not be parsed. - * - * @throws Exception When a test failure occurs. - */ - @Test - void failureWhenNotParseable() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " format 'myrome', {", - " target '**/*.js'", - " rome('12.0.0').language('json')", - " }", - "}"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - - var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - assertThat(spotlessApply.getOutput()).contains("spotlessMyrome FAILED"); - assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertThat(spotlessApply.getOutput()).contains("Format with errors is disabled."); - assertThat(spotlessApply.getOutput()).contains("Step 'rome' found problem in 'rome_test.js'"); - } -} diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f71dda5b39..c5162b39a2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -18,6 +18,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057)) * Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078)) * Bump default `sortpom` version to latest `3.4.1` -> `4.0.0` and support versions back to `3.2.1`. ([#2115](https://github.com/diffplug/spotless/pull/2115)) +### Removed +* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119)) ## [2.43.0] - 2024-01-23 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f003980705..782d685b67 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1332,12 +1332,6 @@ a formatter that for the frontend written in Rust, which has a native binary, do is pretty fast. It can currently format JavaScript, TypeScript, JSX, and JSON, and may support [more frontend languages](https://biomejs.dev/internals/language-support/) such as CSS in the future. -Note: Biome [was formerly called Rome](https://biomejs.dev/blog/annoucing-biome/). Configurations with -the old `` tag and `rome(...)` function are still supported for the time being. This will be removed -in a future version, you should migrate to the new `` tag or `biome(...)` function. The configuration -remains the same, you only need to update the version. If you are using a custom `rome.json` configuration file, -you need to rename it to `biome.json`. - You can use Biome in any language-specific format for supported languages, but usually you will be creating a generic format. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/AbstractBiome.java similarity index 93% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/AbstractBiome.java index da66bf37a0..7bc502edf1 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/AbstractBiome.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.maven.rome; +package com.diffplug.spotless.maven.generic; import java.nio.file.Paths; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.biome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.rome.BiomeFlavor; -import com.diffplug.spotless.rome.RomeStep; /** * Factory for creating the Biome formatter step that can format format code in @@ -32,11 +32,11 @@ * "https://github.com/biomejs/biome">https://github.com/biomejs/biome. It * delegates to the Biome CLI executable. */ -public abstract class AbstractRome implements FormatterStepFactory { +public abstract class AbstractBiome implements FormatterStepFactory { /** Biome flavor to use. */ private BiomeFlavor flavor; - protected AbstractRome(BiomeFlavor flavor) { + protected AbstractBiome(BiomeFlavor flavor) { this.flavor = flavor; } @@ -133,13 +133,13 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { * the currently executed project. * @return A builder for a Biome step. */ - private RomeStep newBuilder(FormatterStepConfig config) { + private BiomeStep newBuilder(FormatterStepConfig config) { if (pathToExe != null) { var resolvedExePath = resolveExePath(config); - return RomeStep.withExePath(flavor, resolvedExePath); + return BiomeStep.withExePath(flavor, resolvedExePath); } else { var downloadDir = resolveDownloadDir(config); - return RomeStep.withExeDownload(flavor, version, downloadDir); + return BiomeStep.withExeDownload(flavor, version, downloadDir); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java index e096a14734..133e21c302 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,15 +17,14 @@ import org.apache.maven.plugins.annotations.Parameter; -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeFlavor; /** * Generic Biome formatter step that detects the language of the input file from * the file name. It should be specified as a formatter step for a generic * {@code }. */ -public class Biome extends AbstractRome { +public class Biome extends AbstractBiome { public Biome() { super(BiomeFlavor.BIOME); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index ce7db9b926..ccdef479cf 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,14 +48,4 @@ public String licenseHeaderDelimiter() { public void addBiome(Biome biome) { addStepFactory(biome); } - - /** - * Adds a step to this format that format code with the Rome formatter. - * @param rome Rome configuration to use. - * @deprecated Rome has transitioned to Biome. Use {@link #addBiome(Biome)}. - */ - @Deprecated - public void addRome(Rome rome) { - addStepFactory(rome); - } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java deleted file mode 100644 index 53080fe546..0000000000 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.maven.generic; - -import org.apache.maven.plugins.annotations.Parameter; - -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; - -/** - * See {@link Biome}. - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ -public class Rome extends AbstractRome { - public Rome() { - super(BiomeFlavor.ROME); - } - - /** - * Gets the language (syntax) of the input files to format. When - * null or the empty string, the language is detected automatically - * from the file name. Currently the following languages are supported by Rome: - *
    - *
      - *
    • js (JavaScript)
    • - *
    • jsx (JavaScript + JSX)
    • - *
    • js? (JavaScript or JavaScript + JSX, depending on the file - * extension)
    • - *
    • ts (TypeScript)
    • - *
    • tsx (TypeScript + JSX)
    • - *
    • ts? (TypeScript or TypeScript + JSX, depending on the file - * extension)
    • - *
    • json (JSON)
    • - *
    - *
- * - * @return The language of the input files. - */ - @Parameter - private String language; - - @Override - protected String getLanguage() { - return language; - } -} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java index 4d52f4cc80..b610a5b63b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package com.diffplug.spotless.maven.javascript; -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeFlavor; +import com.diffplug.spotless.maven.generic.AbstractBiome; /** * Biome formatter step for JavaScript. */ -public class BiomeJs extends AbstractRome { +public class BiomeJs extends AbstractBiome { public BiomeJs() { super(BiomeFlavor.BIOME); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index 3f0a3f959c..dc2949ae68 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,9 +45,4 @@ public void addEslint(EslintJs eslint) { public void addBiome(BiomeJs biome) { addStepFactory(biome); } - - @Deprecated - public void addRome(RomeJs rome) { - addStepFactory(rome); - } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java deleted file mode 100644 index 405809c7a7..0000000000 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2016-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.maven.javascript; - -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; - -/** - * Rome formatter step for JavaScript. - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ -@Deprecated -public class RomeJs extends AbstractRome { - public RomeJs() { - super(BiomeFlavor.ROME); - } - - @Override - protected String getLanguage() { - return "js?"; - } -} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java index a8d329d725..f52b490d69 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package com.diffplug.spotless.maven.json; -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeFlavor; +import com.diffplug.spotless.maven.generic.AbstractBiome; /** * Biome formatter step for JSON. */ -public class BiomeJson extends AbstractRome { +public class BiomeJson extends AbstractBiome { public BiomeJson() { super(BiomeFlavor.BIOME); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 8baf379a5e..80767f41f3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,11 +54,6 @@ public void addBiome(BiomeJson biome) { addStepFactory(biome); } - @Deprecated - public void addRome(RomeJson rome) { - addStepFactory(rome); - } - public void addJsonPatch(JsonPatch jsonPatch) { addStepFactory(jsonPatch); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java deleted file mode 100644 index 2959d5a055..0000000000 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2016-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.maven.json; - -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; - -/** - * Rome formatter step for JSON. - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ -@Deprecated -public class RomeJson extends AbstractRome { - public RomeJson() { - super(BiomeFlavor.ROME); - } - - @Override - protected String getLanguage() { - return "json"; - } -} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java index a99e633a42..e9f84d9edb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package com.diffplug.spotless.maven.typescript; -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; +import com.diffplug.spotless.biome.BiomeFlavor; +import com.diffplug.spotless.maven.generic.AbstractBiome; /** * Biome formatter step for TypeScript. */ -public class BiomeTs extends AbstractRome { +public class BiomeTs extends AbstractBiome { public BiomeTs() { super(BiomeFlavor.BIOME); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java deleted file mode 100644 index f6ea80581d..0000000000 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2016-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.maven.typescript; - -import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.BiomeFlavor; - -/** - * Rome formatter step for TypeScript. - * @deprecated Rome has transitioned to Biome. This will be removed shortly. - */ -@Deprecated -public class RomeTs extends AbstractRome { - public RomeTs() { - super(BiomeFlavor.ROME); - } - - @Override - protected String getLanguage() { - return "ts?"; - } -} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index af25b8c773..2646ca05b0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,9 +49,4 @@ public void addEslint(EslintTs eslint) { public void addBiome(BiomeTs biome) { addStepFactory(biome); } - - @Deprecated - public void addRome(RomeTs rome) { - addStepFactory(rome); - } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java deleted file mode 100644 index f6a8107be1..0000000000 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.maven.rome; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.owasp.encoder.Encode.forXml; - -import org.junit.jupiter.api.Test; - -import com.diffplug.spotless.maven.MavenIntegrationHarness; - -@Deprecated -class RomeMavenTest extends MavenIntegrationHarness { - /** - * Tests that rome can be used as a generic formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asGenericStep() throws Exception { - writePomWithRomeSteps("**/*.js", "12.0.0"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - } - - /** - * Tests that rome can be used as a JavaScript formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asJavaScriptStep() throws Exception { - writePomWithJavascriptSteps("**/*.js", "12.0.0"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - } - - /** - * Tests that rome can be used as a JSON formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asJsonStep() throws Exception { - writePomWithJsonSteps("**/*.json", "12.0.0"); - setFile("rome_test.json").toResource("rome/json/fileBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.json").sameAsResource("rome/json/fileAfter.json"); - } - - /** - * Tests that rome can be used as a TypeScript formatting step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void asTypeScriptStep() throws Exception { - writePomWithTypescriptSteps("**/*.ts", "12.0.0"); - setFile("rome_test.ts").toResource("rome/ts/fileBefore.ts"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.ts").sameAsResource("rome/ts/fileAfter.ts"); - } - - /** - * Tests that the language can be specified for the generic format step. - * - * @throws Exception When a test failure occurs. - */ - @Test - void canSetLanguageForGenericStep() throws Exception { - writePomWithRomeSteps("**/*.nosj", "12.0.0json"); - setFile("rome_test.nosj").toResource("rome/json/fileBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.nosj").sameAsResource("rome/json/fileAfter.json"); - } - - /** - * Tests that an absolute config path can be specified. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathAbsolute() throws Exception { - var path = newFile("configs").getAbsolutePath(); - writePomWithRomeSteps("**/*.js", - "12.0.0" + forXml(path) + ""); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); - } - - /** - * Tests that a path to the directory with the rome.json config file can be - * specified. Uses a config file with a line width of 120. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathLineWidth120() throws Exception { - writePomWithRomeSteps("**/*.js", "12.0.0configs"); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); - } - - /** - * Tests that a path to the directory with the rome.json config file can be - * specified. Uses a config file with a line width of 80. - * - * @throws Exception When a test failure occurs. - */ - @Test - void configPathLineWidth80() throws Exception { - writePomWithRomeSteps("**/*.js", "12.0.0configs"); - setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); - setFile("configs/rome.json").toResource("rome/config/line-width-80.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter80.js"); - } - - /** - * Tests that the download directory can be an absolute path. - * - * @throws Exception When a test failure occurs. - */ - @Test - void downloadDirAbsolute() throws Exception { - var path = newFile("target/bin/rome").getAbsoluteFile().toString(); - writePomWithRomeSteps("**/*.js", - "12.0.0" + forXml(path) + ""); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - assertEquals(2, newFile("target/bin/rome").list().length); - } - - /** - * Tests that the download directory can be changed to a path relative to the - * project's base directory. - * - * @throws Exception When a test failure occurs. - */ - @Test - void downloadDirRelative() throws Exception { - writePomWithRomeSteps("**/*.js", - "12.0.0target/bin/rome"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); - assertEquals(2, newFile("target/bin/rome").list().length); - } - - /** - * Tests that the build fails when the input file could not be parsed. - * - * @throws Exception When a test failure occurs. - */ - @Test - void failureWhenExeNotFound() throws Exception { - writePomWithRomeSteps("**/*.js", "12.0.0rome/is/missing"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - var result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertThat(result.stdOutUtf8()).contains("Biome executable does not exist"); - } - - /** - * Tests that the build fails when the input file could not be parsed. - * - * @throws Exception When a test failure occurs. - */ - @Test - void failureWhenNotParseable() throws Exception { - writePomWithRomeSteps("**/*.js", "12.0.0json"); - setFile("rome_test.js").toResource("rome/js/fileBefore.js"); - var result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertThat(result.stdOutUtf8()).contains("Format with errors is disabled."); - assertThat(result.stdOutUtf8()).contains("Unable to format file"); - assertThat(result.stdOutUtf8()).contains("Step 'rome' found problem in 'rome_test.js'"); - } -} diff --git a/testlib/src/main/resources/rome/config/line-width-120.json b/testlib/src/main/resources/rome/config/line-width-120.json deleted file mode 100644 index 8f14afa3f8..0000000000 --- a/testlib/src/main/resources/rome/config/line-width-120.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "formatter": { - "enabled": true, - "indentStyle": "tab", - "lineWidth": 120, - "formatWithErrors": false - }, - "linter": { - "enabled": false - } - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/config/line-width-80.json b/testlib/src/main/resources/rome/config/line-width-80.json deleted file mode 100644 index 5ec998bd97..0000000000 --- a/testlib/src/main/resources/rome/config/line-width-80.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "formatter": { - "enabled": true, - "indentStyle": "tab", - "lineWidth": 80, - "formatWithErrors": false - }, - "linter": { - "enabled": false - } - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileAfter.cjs b/testlib/src/main/resources/rome/js/fileAfter.cjs deleted file mode 100644 index defc9c85eb..0000000000 --- a/testlib/src/main/resources/rome/js/fileAfter.cjs +++ /dev/null @@ -1,3 +0,0 @@ -function foo(name = "World") { - return "Hello " + name; -} diff --git a/testlib/src/main/resources/rome/js/fileAfter.js b/testlib/src/main/resources/rome/js/fileAfter.js deleted file mode 100644 index defc9c85eb..0000000000 --- a/testlib/src/main/resources/rome/js/fileAfter.js +++ /dev/null @@ -1,3 +0,0 @@ -function foo(name = "World") { - return "Hello " + name; -} diff --git a/testlib/src/main/resources/rome/js/fileAfter.jsx b/testlib/src/main/resources/rome/js/fileAfter.jsx deleted file mode 100644 index 313aceb6ed..0000000000 --- a/testlib/src/main/resources/rome/js/fileAfter.jsx +++ /dev/null @@ -1,3 +0,0 @@ -export function Panel(cfg = {}) { - return
{1 + 2}
; -} diff --git a/testlib/src/main/resources/rome/js/fileAfter.mjs b/testlib/src/main/resources/rome/js/fileAfter.mjs deleted file mode 100644 index defc9c85eb..0000000000 --- a/testlib/src/main/resources/rome/js/fileAfter.mjs +++ /dev/null @@ -1,3 +0,0 @@ -function foo(name = "World") { - return "Hello " + name; -} diff --git a/testlib/src/main/resources/rome/js/fileBefore.cjs b/testlib/src/main/resources/rome/js/fileBefore.cjs deleted file mode 100644 index 92539ba751..0000000000 --- a/testlib/src/main/resources/rome/js/fileBefore.cjs +++ /dev/null @@ -1,3 +0,0 @@ -function foo ( name="World"){ - return "Hello "+name ; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.js b/testlib/src/main/resources/rome/js/fileBefore.js deleted file mode 100644 index 92539ba751..0000000000 --- a/testlib/src/main/resources/rome/js/fileBefore.js +++ /dev/null @@ -1,3 +0,0 @@ -function foo ( name="World"){ - return "Hello "+name ; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.jsx b/testlib/src/main/resources/rome/js/fileBefore.jsx deleted file mode 100644 index 8e5d9834bc..0000000000 --- a/testlib/src/main/resources/rome/js/fileBefore.jsx +++ /dev/null @@ -1,4 +0,0 @@ -export function Panel ( cfg={}){ - return (
{1+2}
- ) ; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.mjs b/testlib/src/main/resources/rome/js/fileBefore.mjs deleted file mode 100644 index 92539ba751..0000000000 --- a/testlib/src/main/resources/rome/js/fileBefore.mjs +++ /dev/null @@ -1,3 +0,0 @@ -function foo ( name="World"){ - return "Hello "+name ; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/longLineAfter120.js b/testlib/src/main/resources/rome/js/longLineAfter120.js deleted file mode 100644 index 68addc4b65..0000000000 --- a/testlib/src/main/resources/rome/js/longLineAfter120.js +++ /dev/null @@ -1 +0,0 @@ -const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; diff --git a/testlib/src/main/resources/rome/js/longLineAfter80.js b/testlib/src/main/resources/rome/js/longLineAfter80.js deleted file mode 100644 index dbdbd157e9..0000000000 --- a/testlib/src/main/resources/rome/js/longLineAfter80.js +++ /dev/null @@ -1,13 +0,0 @@ -const x = [ - "Hello", - "World", - "How", - "Are", - "You", - "Doing", - "Today", - "Such", - "A", - "Wondrous", - "Sunshine", -]; diff --git a/testlib/src/main/resources/rome/js/longLineBefore.js b/testlib/src/main/resources/rome/js/longLineBefore.js deleted file mode 100644 index fd59e429c2..0000000000 --- a/testlib/src/main/resources/rome/js/longLineBefore.js +++ /dev/null @@ -1 +0,0 @@ -const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; \ No newline at end of file diff --git a/testlib/src/main/resources/rome/json/fileAfter.json b/testlib/src/main/resources/rome/json/fileAfter.json deleted file mode 100644 index 468dac3297..0000000000 --- a/testlib/src/main/resources/rome/json/fileAfter.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "a": [1, 2, 3], - "b": 9, - "c": null -} diff --git a/testlib/src/main/resources/rome/json/fileBefore.json b/testlib/src/main/resources/rome/json/fileBefore.json deleted file mode 100644 index 77182284c7..0000000000 --- a/testlib/src/main/resources/rome/json/fileBefore.json +++ /dev/null @@ -1,7 +0,0 @@ - { - "a":[1,2,3 - -], - "b":9, - "c" : null - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileAfter.cts b/testlib/src/main/resources/rome/ts/fileAfter.cts deleted file mode 100644 index f854953234..0000000000 --- a/testlib/src/main/resources/rome/ts/fileAfter.cts +++ /dev/null @@ -1,4 +0,0 @@ -type Name = "World" | "Maven" | "Gradle"; -const foo = (name: Name = "World", v: T): string => { - return "Hello " + name; -}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.mts b/testlib/src/main/resources/rome/ts/fileAfter.mts deleted file mode 100644 index e6563e3030..0000000000 --- a/testlib/src/main/resources/rome/ts/fileAfter.mts +++ /dev/null @@ -1,4 +0,0 @@ -export type Name = "World" | "Maven" | "Gradle"; -export const foo = (name: Name = "World", v: T): string => { - return "Hello " + name; -}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.ts b/testlib/src/main/resources/rome/ts/fileAfter.ts deleted file mode 100644 index e6563e3030..0000000000 --- a/testlib/src/main/resources/rome/ts/fileAfter.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type Name = "World" | "Maven" | "Gradle"; -export const foo = (name: Name = "World", v: T): string => { - return "Hello " + name; -}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.tsx b/testlib/src/main/resources/rome/ts/fileAfter.tsx deleted file mode 100644 index 15ef316142..0000000000 --- a/testlib/src/main/resources/rome/ts/fileAfter.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export interface Cfg { - classname: string; - message: T; -} -const Panel = (cfg: Cfg): JSX.Element => { - return
{String(cfg.message)}
; -}; diff --git a/testlib/src/main/resources/rome/ts/fileBefore.cts b/testlib/src/main/resources/rome/ts/fileBefore.cts deleted file mode 100644 index d4304287c0..0000000000 --- a/testlib/src/main/resources/rome/ts/fileBefore.cts +++ /dev/null @@ -1,4 +0,0 @@ -type Name = "World" | "Maven"|"Gradle"; -const foo = ( name: Name="World", v: T): string => { - return "Hello " + name; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.mts b/testlib/src/main/resources/rome/ts/fileBefore.mts deleted file mode 100644 index 96837762a3..0000000000 --- a/testlib/src/main/resources/rome/ts/fileBefore.mts +++ /dev/null @@ -1,5 +0,0 @@ -export - type Name = "World" | "Maven"|"Gradle"; -export const foo = ( name: Name="World", v: T): string => { - return "Hello " + name; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.ts b/testlib/src/main/resources/rome/ts/fileBefore.ts deleted file mode 100644 index 96837762a3..0000000000 --- a/testlib/src/main/resources/rome/ts/fileBefore.ts +++ /dev/null @@ -1,5 +0,0 @@ -export - type Name = "World" | "Maven"|"Gradle"; -export const foo = ( name: Name="World", v: T): string => { - return "Hello " + name; - } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.tsx b/testlib/src/main/resources/rome/ts/fileBefore.tsx deleted file mode 100644 index 38f24f8440..0000000000 --- a/testlib/src/main/resources/rome/ts/fileBefore.tsx +++ /dev/null @@ -1,8 +0,0 @@ -export interface Cfg{ -classname:string, -message:T, -} -const Panel = ( cfg:Cfg):JSX.Element =>{ - return (
{String(cfg.message)}
- ) ; - } \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/biome/BiomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/biome/BiomeStepTest.java new file mode 100644 index 0000000000..0ad2f68783 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/biome/BiomeStepTest.java @@ -0,0 +1,300 @@ +/* + * Copyright 2023-2024 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.biome; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import com.diffplug.common.base.StandardSystemProperty; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.ThrowingEx; + +class BiomeStepTest extends ResourceHarness { + private static String downloadDir; + + @BeforeAll + static void createDownloadDir() throws IOException { + // We do not want to download Biome each time we execute a test + var userHome = Paths.get(StandardSystemProperty.USER_HOME.value()); + downloadDir = userHome.resolve(".gradle").resolve("rome-dl-test").toAbsolutePath().normalize().toString(); + } + + @Nested + class Biome { + /** + * Tests that files can be formatted without setting the input language + * explicitly. + */ + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); + } + + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); + } + + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); + } + + /** + * Biome is hard-coded to ignore certain files, such as package.json. Since version 1.5.0, + * the biome CLI does not output any formatted code anymore, whereas previously it printed + * the input as-is. This tests checks that when the biome formatter outputs an empty string, + * the contents of the file to format are used instead. + */ + @Test + void preservesIgnoredFiles() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.5.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/json/package.json", "biome/json/packageAfter.json"); + } + } + + @Nested + class ConfigFile { + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth120() { + var path = createBiomeConfig("biome/config/line-width-120.json"); + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter120.js"); + } + + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth80() { + var path = createBiomeConfig("biome/config/line-width-80.json"); + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter80.js"); + } + + private String createBiomeConfig(String name) { + var config = createTestFile(name).toPath(); + var dir = config.getParent(); + var rome = dir.resolve("biome.json"); + ThrowingEx.run(() -> Files.copy(config, rome)); + return dir.toString(); + } + } + + /** + * Tests that files can be formatted when setting the input language explicitly. + */ + @Nested + class ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); + } + + /** + * Tests that a *.json file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); + } + + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = BiomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); + var stepHarness = StepHarnessWithFile.forStep(BiomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); + } + } + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java deleted file mode 100644 index 8ab92e90e0..0000000000 --- a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java +++ /dev/null @@ -1,548 +0,0 @@ -/* - * Copyright 2023-2024 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.rome; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import com.diffplug.common.base.StandardSystemProperty; -import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.StepHarnessWithFile; -import com.diffplug.spotless.ThrowingEx; - -class RomeStepTest extends ResourceHarness { - private static String downloadDir; - - @BeforeAll - static void createDownloadDir() throws IOException { - // We do not want to download Rome each time we execute a test - var userHome = Paths.get(StandardSystemProperty.USER_HOME.value()); - downloadDir = userHome.resolve(".gradle").resolve("rome-dl-test").toAbsolutePath().normalize().toString(); - } - - @Nested - @Deprecated - class Rome { - /** - * Tests that files can be formatted without setting the input language - * explicitly. - */ - @Nested - class AutoDetectLanguage { - /** - * Tests that a *.cjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); - } - - /** - * Tests that a *.cts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); - } - - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); - } - - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); - } - - /** - * Tests that a *.jsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); - } - - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); - } - - /** - * Tests that a *.mts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); - } - - /** - * Tests that a *.ts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); - } - - /** - * Tests that a *.tsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); - } - } - - @Nested - class ConfigFile { - /** - * Test formatting with the line width in the config file set to 120. - */ - @Test - void testLineWidth120() { - var path = createRomeConfig("rome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter120.js"); - } - - /** - * Test formatting with the line width in the config file set to 120. - */ - @Test - void testLineWidth80() { - var path = createRomeConfig("rome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter80.js"); - } - - private String createRomeConfig(String name) { - var config = createTestFile(name).toPath(); - var dir = config.getParent(); - var rome = dir.resolve("rome.json"); - ThrowingEx.run(() -> Files.copy(config, rome)); - return dir.toString(); - } - } - - /** - * Tests that files can be formatted when setting the input language explicitly. - */ - @Nested - class ExplicitLanguage { - /** - * Tests that a *.cjs file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); - } - - /** - * Tests that a *.cts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); - } - - /** - * Tests that a *.js file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); - } - - /** - * Tests that a *.json file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("json").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); - } - - /** - * Tests that a *.jsx file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("jsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); - } - - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); - } - - /** - * Tests that a *.mts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); - } - - /** - * Tests that a *.ts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); - } - - /** - * Tests that a *.tsx file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("tsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); - } - } - } - - @Nested - class Biome { - /** - * Tests that files can be formatted without setting the input language - * explicitly. - */ - @Nested - class AutoDetectLanguage { - /** - * Tests that a *.cjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); - } - - /** - * Tests that a *.cts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); - } - - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); - } - - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); - } - - /** - * Tests that a *.jsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); - } - - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); - } - - /** - * Tests that a *.mts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); - } - - /** - * Tests that a *.ts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); - } - - /** - * Tests that a *.tsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); - } - - /** - * Biome is hard-coded to ignore certain files, such as package.json. Since version 1.5.0, - * the biome CLI does not output any formatted code anymore, whereas previously it printed - * the input as-is. This tests checks that when the biome formatter outputs an empty string, - * the contents of the file to format are used instead. - */ - @Test - void preservesIgnoredFiles() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.5.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/json/package.json", "biome/json/packageAfter.json"); - } - } - - @Nested - class ConfigFile { - /** - * Test formatting with the line width in the config file set to 120. - */ - @Test - void testLineWidth120() { - var path = createBiomeConfig("biome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter120.js"); - } - - /** - * Test formatting with the line width in the config file set to 120. - */ - @Test - void testLineWidth80() { - var path = createBiomeConfig("biome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter80.js"); - } - - private String createBiomeConfig(String name) { - var config = createTestFile(name).toPath(); - var dir = config.getParent(); - var rome = dir.resolve("biome.json"); - ThrowingEx.run(() -> Files.copy(config, rome)); - return dir.toString(); - } - } - - /** - * Tests that files can be formatted when setting the input language explicitly. - */ - @Nested - class ExplicitLanguage { - /** - * Tests that a *.cjs file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); - } - - /** - * Tests that a *.cts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); - } - - /** - * Tests that a *.js file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); - } - - /** - * Tests that a *.json file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); - } - - /** - * Tests that a *.jsx file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); - } - - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); - } - - /** - * Tests that a *.mts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); - } - - /** - * Tests that a *.ts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); - } - - /** - * Tests that a *.tsx file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); - } - } - } -}