From 0abd5c353d773c4118e29014b49a07e01c0c8a8c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:42:22 +0000 Subject: [PATCH 01/60] chore(deps): update plugin com.gradle.enterprise to v3.14.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index b6d227dab8..57c670b977 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.13.3' + id 'com.gradle.enterprise' version '3.14.1' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From b2db0f55af0d5e20435355f2232c6f54ad7458ae Mon Sep 17 00:00:00 2001 From: jochenberger Date: Wed, 2 Aug 2023 15:42:51 +0200 Subject: [PATCH 02/60] Add support for Eclipse 4.28 --- .../spotless/extra/groovy/GrEclipseFormatterStep.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 3b57df889b..0d6287caea 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -50,7 +50,9 @@ protected P2Model model(String version) { throw new IllegalArgumentException("4.8 is the oldest version we support, this was " + version); } String greclipseVersion; - if (eVersion >= 18) { + if (eVersion >= 28) { + greclipseVersion = "5." + (eVersion - 28) + ".0"; + } else if (eVersion >= 18) { greclipseVersion = "4." + (eVersion - 18) + ".0"; } else { greclipseVersion = "3." + (eVersion - 8) + ".0"; From 74d840dc06f8e10cc622cf6b0bd1799e7aa91860 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:08:51 +0200 Subject: [PATCH 03/60] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 2b60913d67..c64220d445 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756)) * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) From effba12acd62aebb8ed66eaed3067289aa556893 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:09:11 +0200 Subject: [PATCH 04/60] Update CHANGES.md --- plugin-gradle/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b21debb36f..4fef72db7e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From 4c568b4f1da656771e5b95d6d77e74d3eedb5d0d Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:09:45 +0200 Subject: [PATCH 05/60] Update CHANGES.md --- plugin-maven/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index bab8fca7b3..e4f3441357 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From d1c663a7ad83e1c9b6a2df0e5bf10f2f8053035d Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:18:12 +0200 Subject: [PATCH 06/60] Fix formatting --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c64220d445..566d13cf94 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756)) * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) From 4c48360ef0b02af8494ea06ac47d382d259fd10e Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:18:31 +0200 Subject: [PATCH 07/60] Fix formatting --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4fef72db7e..bef3d961f8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From 413cac88aa17a435ed55d1de89739fcfc6968e65 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Aug 2023 08:18:49 +0200 Subject: [PATCH 08/60] Fix formatting --- plugin-maven/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e4f3441357..d0977c05bf 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From 14e4e62aa76768e8d9110478731668fe73dec843 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Fri, 4 Aug 2023 07:12:36 +0200 Subject: [PATCH 09/60] Update default to 4.28 --- .../diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 0d6287caea..b79918d555 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -32,7 +32,7 @@ public final class GrEclipseFormatterStep { private GrEclipseFormatterStep() {} private static final String NAME = "eclipse groovy formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.27"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.28"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From 959fd854c36080caa13123de2089ebcb7396adb4 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 24 Aug 2023 09:42:44 +0800 Subject: [PATCH 10/60] Check if EditorConfig file exist for Ktlint --- plugin-gradle/CHANGES.md | 1 + .../gradle/spotless/KotlinExtension.java | 10 +++++--- .../gradle/spotless/KotlinExtensionTest.java | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1ce2f06a42..27d60e7270 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index f2c3a29d75..27d93717f4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -85,11 +85,15 @@ public class KotlinFormatExtension { addStep(createStep()); } - public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException { - if (editorConfigFile == null) { + public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { + if (editorConfigPath == null) { this.editorConfigPath = null; } else { - this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigFile)); + File editorConfigFile = getProject().file(editorConfigPath); + if (!editorConfigFile.exists()) { + throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); + } + this.editorConfigPath = FileSignature.signAsList(editorConfigFile); } replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 10fbe5bd90..98e2259be4 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,6 +15,9 @@ */ package com.diffplug.gradle.spotless; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; import java.io.IOException; import org.junit.jupiter.api.Test; @@ -81,6 +84,27 @@ void withExperimentalEditorConfigOverride() throws IOException { assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } + @Test + void testWithInvalidEditorConfigFile() throws IOException { + String invalidPath = "invalid/path/to/.editorconfig".replace('/', File.separatorChar); + + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().setEditorConfigPath('" + invalidPath + "')", + " }", + "}"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + String buildOutput = gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput(); + assertTrue(buildOutput.contains("EditorConfig file does not exist: ")); + assertTrue(buildOutput.contains(invalidPath)); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( From b3c59f7d4b9e214c3f4c14d9333b816e3a90a34b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Aug 2023 12:31:36 -0700 Subject: [PATCH 11/60] Fix on windows. --- .../com/diffplug/gradle/spotless/KotlinExtensionTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 98e2259be4..1c23728244 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,7 +15,7 @@ */ package com.diffplug.gradle.spotless; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -96,13 +96,13 @@ void testWithInvalidEditorConfigFile() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlin {", - " ktlint().setEditorConfigPath('" + invalidPath + "')", + " ktlint().setEditorConfigPath('" + invalidPath.replace("\\", "\\\\") + "')", " }", "}"); setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); String buildOutput = gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput(); - assertTrue(buildOutput.contains("EditorConfig file does not exist: ")); - assertTrue(buildOutput.contains(invalidPath)); + assertThat(buildOutput).contains("EditorConfig file does not exist: "); + assertThat(buildOutput).contains(invalidPath); } @Test From 62a957e51b723b3572bbe4beef9255e910d9c036 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Aug 2023 12:31:48 -0700 Subject: [PATCH 12/60] Categorize as fix rather than new feature. --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 27d60e7270..2a5bd5db46 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,12 +6,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) -* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) * Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644)) * Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779)) +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788) ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) From 83aace9d39b7037a430945e152b72580797c2a8a Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 25 Aug 2023 09:35:35 +0800 Subject: [PATCH 13/60] Fix changelog link formats --- CHANGES.md | 4 ++-- plugin-gradle/CHANGES.md | 8 ++++---- plugin-maven/CHANGES.md | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 81af46a526..905a78b8e6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,8 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) ### Fixed * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756)) -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2a5bd5db46..4e7f0d21be 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,11 +7,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) ### Fixed -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) * Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644)) -* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779)) -* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788) +* Fix configuration cache failure when formatting proto files with Buf. ([#1779](https://github.com/diffplug/spotless/pull/1779)) +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)) ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 65a557b14f..d5526dd3c6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,8 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) ### Fixed -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) From c23f89b5f01c2f8366ef127665351bc83bf10bd7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 28 Aug 2023 23:16:54 -0700 Subject: [PATCH 14/60] Update changelogs. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fd8bbb4875..12b8609f82 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ## [2.40.0] - 2023-07-17 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a04bf7987b..4d9832ebf5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -15,7 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775)) +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ## [6.20.0] - 2023-07-17 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5da66951fd..8278e16792 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,12 +5,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) +* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) ### Changes * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775)) ## [2.38.0] - 2023-07-17 ### Added @@ -22,7 +24,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. -* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) ## [2.37.0] - 2023-05-24 ### Added From 7e574c6159954115ced357f0e5e1f0adcf9e3e24 Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 29 Aug 2023 06:44:20 +0000 Subject: [PATCH 15/60] Published lib/2.41.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 12b8609f82..1d78e8d932 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.41.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) From f19cc96927fb50364cbc384ce5e8e2832f0f9ff8 Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 29 Aug 2023 06:47:16 +0000 Subject: [PATCH 16/60] Published gradle/6.21.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 54 ++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4d9832ebf5..eab7e32b2d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.21.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index dbc61207e5..944c07bb6e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.20.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.21.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -127,10 +127,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -300,8 +300,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -351,8 +351,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -422,7 +422,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -454,7 +454,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -486,7 +486,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -522,7 +522,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -554,7 +554,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -575,7 +575,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -600,7 +600,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -640,7 +640,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -734,7 +734,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -799,7 +799,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -919,7 +919,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -951,7 +951,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) +- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) ```gradle spotless { @@ -1339,7 +1339,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1419,9 +1419,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1454,11 +1454,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From c360e81278d909cbe86630df29cfb9d253f38e41 Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 29 Aug 2023 06:49:30 +0000 Subject: [PATCH 17/60] Published maven/2.39.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8278e16792..f932806fcc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.39.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index cb770099ac..74872ef61f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.38.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.38.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.39.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.39.0/index.html) true + false com.google.googlejavaformat:google-java-format From 493a3b6097773167751c711d8efaade9651a4bc9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:52:03 +0000 Subject: [PATCH 23/60] Update plugin com.gradle.plugin-publish to v1.2.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 57c670b977..a24c6d24d5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.18.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.2.0' apply false + id 'com.gradle.plugin-publish' version '1.2.1' apply false // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From ef8829e4d13d7f335d5178209ca85410376432ce Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Sat, 2 Sep 2023 15:32:54 -0400 Subject: [PATCH 24/60] feat: add flexmark gradle support --- CHANGES.md | 3 + README.md | 4 +- .../spotless/markdown/FlexmarkStep.java | 2 +- plugin-gradle/CHANGES.md | 3 + plugin-gradle/README.md | 20 +++++ .../gradle/spotless/FlexmarkExtension.java | 74 +++++++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 6 ++ .../spotless/FlexmarkExtensionTest.java | 41 ++++++++++ 8 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java diff --git a/CHANGES.md b/CHANGES.md index 1d78e8d932..8150fefcbb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Changes +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. + ## [2.41.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) diff --git a/README.md b/README.md index cd1e736014..5c3221b1b4 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', -lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('markdown.FlexmarkStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -146,7 +146,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | -| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java index 263931693e..b4159830e7 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java @@ -29,7 +29,7 @@ public class FlexmarkStep { // prevent direct instantiation private FlexmarkStep() {} - private static final String DEFAULT_VERSION = "0.64.0"; + private static final String DEFAULT_VERSION = "0.64.6"; private static final String NAME = "flexmark-java"; private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eab7e32b2d..791b27dafe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added +* Support `flexmark` in gradle. Previously only Maven was supported. + ## [6.21.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 944c07bb6e..367634e63e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -62,6 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format)) - [Python](#python) ([black](#black)) - [FreshMark](#freshmark) aka markdown + - [FlexMark](#flexmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) @@ -573,6 +574,25 @@ spotless { } ``` +## Flexmark + +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) + +[homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). + +Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`. + +To apply flexmark to all of the `.md` files in your project, use this snippet: + +```gradle +spotless { + flexmark { + target '**/*.md' // you have to set the target manually + flexmarkFormatter() // or flexmarkFormatter('0.64.6') // version is optional + } +} +``` + ## Antlr4 `com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java new file mode 100644 index 0000000000..feee2c4801 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java @@ -0,0 +1,74 @@ +/* + * 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.gradle.spotless; + +import java.util.Objects; + +import javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.markdown.FlexmarkStep; + +public class FlexmarkExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { + static final String NAME = "flexmark"; + + @Inject + public FlexmarkExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, null); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, null); + } + + public FlexmarkFormatterConfig flexmarkFormatter() { + return flexmarkFormatter(FlexmarkStep.defaultVersion()); + } + + public FlexmarkFormatterConfig flexmarkFormatter(String version) { + return new FlexmarkFormatterConfig(version); + } + + @Override + protected void setupTask(SpotlessTask task) { + // defaults to all markdown files + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } + + public class FlexmarkFormatterConfig { + + private final String version; + + FlexmarkFormatterConfig(String version) { + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } + + private FormatterStep createStep() { + return FlexmarkStep.create(this.version, provisioner()); + } + } + +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index c3cf5123c0..838231c9f8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -147,6 +147,12 @@ public void freshmark(Action closure) { format(FreshMarkExtension.NAME, FreshMarkExtension.class, closure); } + /** Configures the special flexmark-specific extension. */ + public void flexmark(Action closure) { + requireNonNull(closure); + format(FlexmarkExtension.NAME, FlexmarkExtension.class, closure); + } + /** Configures the special groovy-specific extension. */ public void groovy(Action closure) { format(GroovyExtension.NAME, GroovyExtension.class, closure); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java new file mode 100644 index 0000000000..873baba744 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java @@ -0,0 +1,41 @@ +/* + * 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.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class FlexmarkExtensionTest extends GradleIntegrationHarness { + @Test + void integration() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " flexmark {", + " target '*.md'", + " flexmarkFormatter()", + " }", + "}"); + setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md"); + } +} From ad04a62362ccec2cd8d5975f0326bb57b0bbbf5b Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Sat, 2 Sep 2023 15:37:32 -0400 Subject: [PATCH 25/60] docs: update docs/changes --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-gradle/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8150fefcbb..711bcf819c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) ## [2.41.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 791b27dafe..736909025e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Support `flexmark` in gradle. Previously only Maven was supported. +* Support `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801)) ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 367634e63e..f2781561a0 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -576,7 +576,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). From 9be41217c90032ecb2960e35fd9bef8c189b10d8 Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Sat, 2 Sep 2023 15:43:27 -0400 Subject: [PATCH 26/60] docs: remove copy/paste reference --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f2781561a0..91def5ad5f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -578,7 +578,7 @@ spotless { `com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) -[homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). +[homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`. From d469a3548b6e85dda82d15e466d48f4e0c12fade Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:19:04 -0400 Subject: [PATCH 27/60] feat: add support for prettier v3 plugin changes --- CHANGES.md | 3 + .../spotless/npm/PrettierRestService.java | 12 ++ plugin-gradle/CHANGES.md | 3 + plugin-gradle/README.md | 2 + .../spotless/PrettierIntegrationTest.java | 184 ++++++++++++++---- plugin-maven/CHANGES.md | 3 + plugin-maven/README.md | 2 + .../spotless/maven/generic/Prettier.java | 5 + .../prettier/PrettierFormatStepTest.java | 50 +++++ .../config/.prettierrc_java_plugin.yml | 3 + 10 files changed, 228 insertions(+), 39 deletions(-) create mode 100644 testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml diff --git a/CHANGES.md b/CHANGES.md index 1d78e8d932..652e4ce38c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) + ## [2.41.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index ccdc189d27..a517a7219b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -17,7 +17,9 @@ import java.io.File; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class PrettierRestService extends BaseNpmRestService { @@ -31,6 +33,16 @@ public String resolveConfig(File prettierConfigPath, Map prettie jsonProperties.put("prettier_config_path", prettierConfigPath.getAbsolutePath()); } if (prettierConfigOptions != null) { + // Prettier 3.x plugins support + if (prettierConfigOptions.get("plugins") instanceof List) { + try { + var pluginArray = (List) prettierConfigOptions.get("plugins"); + var pluginsJson = pluginArray.stream().map(e -> '"' + e + '"').collect(Collectors.joining(",", "[", "]")); + prettierConfigOptions.put("plugins", JsonRawValue.wrap(pluginsJson)); + } catch (ClassCastException e) { + throw new IllegalArgumentException("Only values of type 'List' are supported for plugins."); + } + } jsonProperties.put("prettier_config_options", SimpleJsonWriter.of(prettierConfigOptions).toJsonRawValue()); } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eab7e32b2d..989b4ece12 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) + ## [6.21.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 944c07bb6e..2253557f3a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1024,10 +1024,12 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos spotless { java { prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4]) + // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 } format 'php', { target 'src/**/*.php' prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3]) + // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 } } ``` diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 4d5069c1b5..ed32900db0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -19,14 +19,22 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import com.diffplug.spotless.npm.PrettierFormatterStep; import com.diffplug.spotless.tag.NpmTest; @NpmTest class PrettierIntegrationTest extends GradleIntegrationHarness { - @Test - void useInlineConfig() throws IOException { + + private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION; + + private static final String PRETTIER_VERSION_3 = "3.0.3"; + + @ParameterizedTest(name = "{index}: useInlineConfig with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void useInlineConfig(String prettierVersion) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -38,17 +46,25 @@ void useInlineConfig() throws IOException { "spotless {", " format 'mytypescript', {", " target 'test.ts'", - " prettier().config(prettierConfig)", + " prettier('" + prettierVersion + "').config(prettierConfig)", " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); + switch (prettierVersion) { + case PRETTIER_VERSION_2: + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); + break; + case PRETTIER_VERSION_3: + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_3.clean"); + break; + } } - @Test - void verifyCleanSpotlessCheckWorks() throws IOException { + @ParameterizedTest(name = "{index}: verifyCleanSpotlessCheckWorks with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void verifyCleanSpotlessCheckWorks(String prettierVersion) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -60,7 +76,7 @@ void verifyCleanSpotlessCheckWorks() throws IOException { "spotless {", " format 'mytypescript', {", " target 'test.ts'", - " prettier().config(prettierConfig)", + " prettier('" + prettierVersion + "').config(prettierConfig)", " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); @@ -71,8 +87,9 @@ void verifyCleanSpotlessCheckWorks() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessCheck").build(); } - @Test - void useFileConfig() throws IOException { + @ParameterizedTest(name = "{index}: useFileConfig with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void useFileConfig(String prettierVersion) throws IOException { setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc.yml"); setFile("build.gradle").toLines( "plugins {", @@ -82,17 +99,25 @@ void useFileConfig() throws IOException { "spotless {", " format 'mytypescript', {", " target 'test.ts'", - " prettier().configFile('.prettierrc.yml')", + " prettier('" + prettierVersion + "').configFile('.prettierrc.yml')", " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); + switch (prettierVersion) { + case PRETTIER_VERSION_2: + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); + break; + case PRETTIER_VERSION_3: + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_3.clean"); + break; + } } - @Test - void chooseParserBasedOnFilename() throws IOException { + @ParameterizedTest(name = "{index}: chooseParserBasedOnFilename with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void chooseParserBasedOnFilename(String prettierVersion) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -101,7 +126,7 @@ void chooseParserBasedOnFilename() throws IOException { "spotless {", " format 'webResources', {", " target 'dirty.*'", - " prettier()", + " prettier('" + prettierVersion + "')", " }", "}"); setFile("dirty.json").toResource("npm/prettier/filename/dirty.json"); @@ -110,8 +135,20 @@ void chooseParserBasedOnFilename() throws IOException { assertFile("dirty.json").sameAsResource("npm/prettier/filename/clean.json"); } - @Test - void useJavaCommunityPlugin() throws IOException { + @ParameterizedTest(name = "{index}: useJavaCommunityPlugin with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void useJavaCommunityPlugin(String prettierVersion) throws IOException { + var prettierPluginJava = ""; + var prettierConfigPluginsStr = ""; + switch (prettierVersion) { + case PRETTIER_VERSION_2: + prettierPluginJava = "2.1.0"; // last version to support v2 + break; + case PRETTIER_VERSION_3: + prettierPluginJava = "2.3.0"; // latest to support v3 + prettierConfigPluginsStr = "prettierConfig['plugins'] = ['prettier-plugin-java']"; + break; + } setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -120,9 +157,10 @@ void useJavaCommunityPlugin() throws IOException { "def prettierConfig = [:]", "prettierConfig['tabWidth'] = 4", "prettierConfig['parser'] = 'java'", + prettierConfigPluginsStr, "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.8.8'", - "prettierPackages['prettier-plugin-java'] = '2.2.0'", + "prettierPackages['prettier'] = '" + prettierVersion + "'", + "prettierPackages['prettier-plugin-java'] = '" + prettierPluginJava + "'", "spotless {", " format 'java', {", " target 'JavaTest.java'", @@ -135,8 +173,42 @@ void useJavaCommunityPlugin() throws IOException { assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } - @Test - void suggestsMissingJavaCommunityPlugin() throws IOException { + @ParameterizedTest(name = "{index}: useJavaCommunityPluginFileConfig with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void useJavaCommunityPluginFileConfig(String prettierVersion) throws IOException { + var prettierPluginJava = ""; + switch (prettierVersion) { + case PRETTIER_VERSION_2: + prettierPluginJava = "2.1.0"; // last version to support v2 + break; + case PRETTIER_VERSION_3: + prettierPluginJava = "2.3.0"; // latest to support v3 + break; + } + setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc_java_plugin.yml"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierPackages = [:]", + "prettierPackages['prettier'] = '" + prettierVersion + "'", + "prettierPackages['prettier-plugin-java'] = '" + prettierPluginJava + "'", + "spotless {", + " format 'java', {", + " target 'JavaTest.java'", + " prettier(prettierPackages).configFile('.prettierrc.yml')", + " }", + "}"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + } + + @ParameterizedTest(name = "{index}: suggestsMissingJavaCommunityPlugin with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void suggestsMissingJavaCommunityPlugin(String prettierVersion) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -145,7 +217,7 @@ void suggestsMissingJavaCommunityPlugin() throws IOException { "def prettierConfig = [:]", "prettierConfig['tabWidth'] = 4", "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.8.8'", + "prettierPackages['prettier'] = '" + prettierVersion + "'", "spotless {", " format 'java', {", " target 'JavaTest.java'", @@ -158,8 +230,20 @@ void suggestsMissingJavaCommunityPlugin() throws IOException { Assertions.assertThat(spotlessApply.getOutput()).contains("prettier-plugin-java"); } - @Test - void usePhpCommunityPlugin() throws IOException { + @ParameterizedTest(name = "{index}: usePhpCommunityPlugin with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void usePhpCommunityPlugin(String prettierVersion) throws IOException { + var prettierPluginPhp = ""; + var prettierConfigPluginsStr = ""; + switch (prettierVersion) { + case PRETTIER_VERSION_2: + prettierPluginPhp = "0.19.7"; // last version to support v2 + break; + case PRETTIER_VERSION_3: + prettierPluginPhp = "0.20.1"; // latest to support v3 + prettierConfigPluginsStr = "prettierConfig['plugins'] = ['@prettier/plugin-php']"; + break; + } setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -168,9 +252,10 @@ void usePhpCommunityPlugin() throws IOException { "def prettierConfig = [:]", "prettierConfig['tabWidth'] = 3", "prettierConfig['parser'] = 'php'", + prettierConfigPluginsStr, "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.8.8'", - "prettierPackages['@prettier/plugin-php'] = '0.19.6'", + "prettierPackages['prettier'] = '" + prettierVersion + "'", + "prettierPackages['@prettier/plugin-php'] = '" + prettierPluginPhp + "'", "spotless {", " format 'php', {", " target 'php-example.php'", @@ -188,8 +273,25 @@ void usePhpCommunityPlugin() throws IOException { * * @see Issue #1162 on github */ - @Test - void usePhpAndJavaCommunityPlugin() throws IOException { + @ParameterizedTest(name = "{index}: usePhpAndJavaCommunityPlugin with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void usePhpAndJavaCommunityPlugin(String prettierVersion) throws IOException { + var prettierPluginJava = ""; + var prettierPluginPhp = ""; + var prettierConfigPluginsJavaStr = ""; + var prettierConfigPluginsPhpStr = ""; + switch (prettierVersion) { + case PRETTIER_VERSION_2: + prettierPluginJava = "2.1.0"; // last version to support v2 + prettierPluginPhp = "0.19.7"; // last version to support v2 + break; + case PRETTIER_VERSION_3: + prettierPluginJava = "2.3.0"; // latest to support v3 + prettierPluginPhp = "0.20.1"; // latest to support v3 + prettierConfigPluginsJavaStr = "prettierConfigJava['plugins'] = ['prettier-plugin-java']"; + prettierConfigPluginsPhpStr = "prettierConfigPhp['plugins'] = ['@prettier/plugin-php']"; + break; + } setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -198,15 +300,17 @@ void usePhpAndJavaCommunityPlugin() throws IOException { "def prettierConfigPhp = [:]", "prettierConfigPhp['tabWidth'] = 3", "prettierConfigPhp['parser'] = 'php'", + prettierConfigPluginsPhpStr, "def prettierPackagesPhp = [:]", - "prettierPackagesPhp['prettier'] = '2.8.8'", - "prettierPackagesPhp['@prettier/plugin-php'] = '0.19.6'", + "prettierPackagesPhp['prettier'] = '" + prettierVersion + "'", + "prettierPackagesPhp['@prettier/plugin-php'] = '" + prettierPluginPhp + "'", "def prettierConfigJava = [:]", "prettierConfigJava['tabWidth'] = 4", "prettierConfigJava['parser'] = 'java'", + prettierConfigPluginsJavaStr, "def prettierPackagesJava = [:]", - "prettierPackagesJava['prettier'] = '2.8.8'", - "prettierPackagesJava['prettier-plugin-java'] = '2.2.0'", + "prettierPackagesJava['prettier'] = '" + prettierVersion + "'", + "prettierPackagesJava['prettier-plugin-java'] = '" + prettierPluginJava + "'", "spotless {", " format 'php', {", " target 'php-example.php'", @@ -227,8 +331,9 @@ void usePhpAndJavaCommunityPlugin() throws IOException { assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } - @Test - void autodetectNpmrcFileConfig() throws IOException { + @ParameterizedTest(name = "{index}: autodetectNpmrcFileConfig with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void autodetectNpmrcFileConfig(String prettierVersion) throws IOException { setFile(".npmrc").toLines( "registry=https://i.do.not.exist.com", "fetch-timeout=250", @@ -245,7 +350,7 @@ void autodetectNpmrcFileConfig() throws IOException { "spotless {", " format 'mytypescript', {", " target 'test.ts'", - " prettier().config(prettierConfig)", + " prettier('" + prettierVersion + "').config(prettierConfig)", " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); @@ -253,8 +358,9 @@ void autodetectNpmrcFileConfig() throws IOException { Assertions.assertThat(spotlessApply.getOutput()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } - @Test - void pickupNpmrcFileConfig() throws IOException { + @ParameterizedTest(name = "{index}: autodetectNpmrcFileConfig with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void pickupNpmrcFileConfig(String prettierVersion) throws IOException { setFile(".custom_npmrc").toLines( "registry=https://i.do.not.exist.com", "fetch-timeout=250", @@ -271,7 +377,7 @@ void pickupNpmrcFileConfig() throws IOException { "spotless {", " format 'mytypescript', {", " target 'test.ts'", - " prettier().npmrc('.custom_npmrc').config(prettierConfig)", + " prettier('" + prettierVersion + "').npmrc('.custom_npmrc').config(prettierConfig)", " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f932806fcc..b624299e71 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) + ## [2.39.0] - 2023-08-29 ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 74872ef61f..1dc78a5667 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1074,6 +1074,8 @@ You can use prettier in any language-specific format, but usually you will be cr ${project.basedir}/path/to/configfile true + + @prettier/plugin-php diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index e92b2814bd..c6b3e46e3c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -85,6 +85,11 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { if (Boolean.TRUE.toString().equalsIgnoreCase(entry.getValue()) || Boolean.FALSE.toString().equalsIgnoreCase(entry.getValue())) { return new AbstractMap.SimpleEntry<>(entry.getKey(), Boolean.parseBoolean(entry.getValue())); } + // Prettier v3 - plugins config will be a comma delimited list of plugins + if (entry.getKey().equals("plugins")) { + List values = entry.getValue().isEmpty() ? List.of() : Arrays.asList(entry.getValue().split(",")); + return new AbstractMap.SimpleEntry<>(entry.getKey(), values); + } return entry; }) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 9cd1a313eb..abba35e72c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -184,6 +184,56 @@ void custom_plugin() throws Exception { assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); } + @Test + void custom_plugin_prettier3() throws Exception { + writePomWithFormatSteps( + "php-example.php", + "", + " ", + " ", + " prettier", + " 3.0.3", + " ", + " ", + " @prettier/plugin-php", + " 0.20.1", + " ", + " ", + " ", + " 3", + " php", + " @prettier/plugin-php", + " ", + ""); + + setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + } + + @Test + void custom_plugin_prettier3_file_config() throws Exception { + writePomWithFormatSteps( + "JavaTest.java", + "", + " ", + " ", + " prettier", + " 3.0.3", + " ", + " ", + " prettier-plugin-java", + " 2.3.0", + " ", + " ", + " .prettierrc.yml", + ""); + setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc_java_plugin.yml"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + } + @Test void autodetect_parser_based_on_filename() throws Exception { writePomWithFormatSteps( diff --git a/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml b/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml new file mode 100644 index 0000000000..3f7a801335 --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml @@ -0,0 +1,3 @@ +parser: java +tabWidth: 4 +plugins: ['prettier-plugin-java'] From d5db9148e47a61e4f814af58b90228414cd2b833 Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:27:21 -0400 Subject: [PATCH 28/60] fix: add final back to BuildResult --- .../com/diffplug/gradle/spotless/PrettierIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index ed32900db0..74b6db9167 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -50,7 +50,7 @@ void useInlineConfig(String prettierVersion) throws IOException { " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); switch (prettierVersion) { case PRETTIER_VERSION_2: @@ -80,7 +80,7 @@ void verifyCleanSpotlessCheckWorks(String prettierVersion) throws IOException { " }", "}"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - BuildResult spotlessCheckFailsGracefully = gradleRunner().withArguments("--stacktrace", "spotlessCheck").buildAndFail(); + final BuildResult spotlessCheckFailsGracefully = gradleRunner().withArguments("--stacktrace", "spotlessCheck").buildAndFail(); Assertions.assertThat(spotlessCheckFailsGracefully.getOutput()).contains("> The following files had format violations:"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); From 3226165b74c32c00dcdce8deeecbf7c23283fe3c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 3 Sep 2023 20:22:00 +0200 Subject: [PATCH 29/60] feat: add support for nested lists in json writer opt for supporting lists/arrays as first level citizen in json serialization for configs in npm-based formatters. --- .../diffplug/spotless/npm/JsonEscaper.java | 18 +++++- ...{SimpleJsonWriter.java => JsonWriter.java} | 33 +++++++---- .../spotless/npm/ListableAdapter.java | 58 +++++++++++++++++++ .../spotless/npm/PrettierRestService.java | 15 +---- .../spotless/npm/SimpleRestClient.java | 4 +- .../spotless/npm/TsFmtFormatterStep.java | 2 +- .../spotless/npm/TsFmtRestService.java | 2 +- ...sonWriterTest.java => JsonWriterTest.java} | 6 +- 8 files changed, 106 insertions(+), 32 deletions(-) rename lib/src/main/java/com/diffplug/spotless/npm/{SimpleJsonWriter.java => JsonWriter.java} (77%) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java rename testlib/src/test/java/com/diffplug/spotless/npm/{SimpleJsonWriterTest.java => JsonWriterTest.java} (93%) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java index 163818d0e7..3ac20d892b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * 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. @@ -34,6 +34,22 @@ public static String jsonEscape(Object val) { if (val instanceof String) { return jsonEscape((String) val); } + if (ListableAdapter.canAdapt(val)) { + // create an array + StringBuilder sb = new StringBuilder(); + sb.append('['); + boolean first = true; + for (Object o : ListableAdapter.adapt(val)) { + if (first) { + first = false; + } else { + sb.append(", "); + } + sb.append(jsonEscape(o)); + } + sb.append(']'); + return sb.toString(); + } return val.toString(); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java b/lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java similarity index 77% rename from lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java rename to lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java index 846f7f1cf3..bbdf9b63d4 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * 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. @@ -28,33 +28,46 @@ import com.diffplug.spotless.ThrowingEx; -public class SimpleJsonWriter { +class JsonWriter { private final LinkedHashMap valueMap = new LinkedHashMap<>(); - public static SimpleJsonWriter of(Map values) { - SimpleJsonWriter writer = new SimpleJsonWriter(); + public static JsonWriter of(Map values) { + JsonWriter writer = new JsonWriter(); writer.putAll(values); return writer; } - SimpleJsonWriter putAll(Map values) { + JsonWriter putAll(Map values) { verifyValues(values); this.valueMap.putAll(values); return this; } - SimpleJsonWriter put(String name, Object value) { + JsonWriter put(String name, Object value) { verifyValues(Collections.singletonMap(name, value)); this.valueMap.put(name, value); return this; } private void verifyValues(Map values) { - if (values.values() - .stream() - .anyMatch(val -> !(val instanceof String || val instanceof JsonRawValue || val instanceof Number || val instanceof Boolean))) { - throw new IllegalArgumentException("Only values of type 'String', 'JsonRawValue', 'Number' and 'Boolean' are supported. You provided: " + values.values()); + for (Object value : values.values()) { + verifyValue(value); + } + } + + private void verifyValue(Object val) { + if (val == null) { + return; + } + if (ListableAdapter.canAdapt(val)) { + for (Object o : ListableAdapter.adapt(val)) { + verifyValue(o); + } + return; + } + if (!(val instanceof String || val instanceof JsonRawValue || val instanceof Number || val instanceof Boolean)) { + throw new IllegalArgumentException("Only values of type 'String', 'JsonRawValue', 'Number' and 'Boolean' are supported. You provided: " + val); } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java new file mode 100644 index 0000000000..3e05e8e51c --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java @@ -0,0 +1,58 @@ +/* + * 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.npm; + +import javax.annotation.Nonnull; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +class ListableAdapter implements Iterable { + + private final List delegate; + + @SuppressWarnings("unchecked") + private ListableAdapter(Object delegate) { + Objects.requireNonNull(delegate); + if (!canAdapt(delegate)) { + throw new IllegalArgumentException("Cannot create ListableAdapter from " + delegate.getClass() + ". Use canAdapt() to check first."); + } + if (delegate instanceof List) { + this.delegate = (List) delegate; + } else if (delegate.getClass().isArray()) { + this.delegate = Arrays.asList((T[]) delegate); + } else { + throw new IllegalArgumentException("Cannot create IterableAdapter from " + delegate.getClass()); + } + } + + static Iterable adapt(Object delegate) { + return new ListableAdapter<>(delegate); + } + + @Override + @Nonnull + public Iterator iterator() { + return delegate.iterator(); + } + + static boolean canAdapt(Object delegate) { + Objects.requireNonNull(delegate); + return delegate instanceof List || delegate.getClass().isArray(); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index a517a7219b..11fd29c68a 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -17,9 +17,7 @@ import java.io.File; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class PrettierRestService extends BaseNpmRestService { @@ -33,18 +31,7 @@ public String resolveConfig(File prettierConfigPath, Map prettie jsonProperties.put("prettier_config_path", prettierConfigPath.getAbsolutePath()); } if (prettierConfigOptions != null) { - // Prettier 3.x plugins support - if (prettierConfigOptions.get("plugins") instanceof List) { - try { - var pluginArray = (List) prettierConfigOptions.get("plugins"); - var pluginsJson = pluginArray.stream().map(e -> '"' + e + '"').collect(Collectors.joining(",", "[", "]")); - prettierConfigOptions.put("plugins", JsonRawValue.wrap(pluginsJson)); - } catch (ClassCastException e) { - throw new IllegalArgumentException("Only values of type 'List' are supported for plugins."); - } - } - jsonProperties.put("prettier_config_options", SimpleJsonWriter.of(prettierConfigOptions).toJsonRawValue()); - + jsonProperties.put("prettier_config_options", JsonWriter.of(prettierConfigOptions).toJsonRawValue()); } return restClient.postJson("/prettier/config-options", jsonProperties); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java index 561839c757..2f413e4b3a 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * 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. @@ -40,7 +40,7 @@ static SimpleRestClient forBaseUrl(String baseUrl) { } String postJson(String endpoint, Map jsonParams) throws SimpleRestException { - final SimpleJsonWriter jsonWriter = SimpleJsonWriter.of(jsonParams); + final JsonWriter jsonWriter = JsonWriter.of(jsonParams); final String jsonString = jsonWriter.toJsonString(); return postJson(endpoint, jsonString); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index a83c3e202a..6b55610be0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -107,7 +107,7 @@ private Map unifyOptions() { Map unified = new HashMap<>(); if (!this.inlineTsFmtSettings.isEmpty()) { File targetFile = new File(this.buildDir, "inline-tsfmt.json"); - SimpleJsonWriter.of(this.inlineTsFmtSettings).toJsonFile(targetFile); + JsonWriter.of(this.inlineTsFmtSettings).toJsonFile(targetFile); unified.put("tsfmt", true); unified.put("tsfmtFile", targetFile.getAbsolutePath()); } else if (this.configFile != null) { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java index 704d2b47af..61a53b4637 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java @@ -28,7 +28,7 @@ public String format(String fileContent, Map configOptions) { Map jsonProperties = new LinkedHashMap<>(); jsonProperties.put("file_content", fileContent); if (configOptions != null && !configOptions.isEmpty()) { - jsonProperties.put("config_options", SimpleJsonWriter.of(configOptions).toJsonRawValue()); + jsonProperties.put("config_options", JsonWriter.of(configOptions).toJsonRawValue()); } return restClient.postJson("/tsfmt/format", jsonProperties); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.java similarity index 93% rename from testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java rename to testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.java index 34d7966709..cb1719c0f3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * 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. @@ -26,9 +26,9 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.ResourceHarness; -class SimpleJsonWriterTest extends ResourceHarness { +class JsonWriterTest extends ResourceHarness { - private SimpleJsonWriter jsonWriter = new SimpleJsonWriter(); + private JsonWriter jsonWriter = new JsonWriter(); @Test void itWritesAValidEmptyObject() { From 6fbb6505790be5103a96a4385eb33095046e1163 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 3 Sep 2023 20:32:58 +0200 Subject: [PATCH 30/60] docs: make explicit and add maven doc --- plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2253557f3a..fcdcfc213a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1024,12 +1024,12 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos spotless { java { prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4]) - // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 + // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 requires additional 'plugins' config } format 'php', { target 'src/**/*.php' prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3]) - // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 + // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 requires additional 'plugins' config } } ``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 1dc78a5667..8f91d8b08b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1121,6 +1121,7 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos 4 java + prettier-plugin-java @@ -1146,6 +1147,7 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos 3 php + @prettier/plugin-php From 3754eb12d3da00be2da0cdadd3123e11ae63af9b Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 4 Sep 2023 15:02:11 +0200 Subject: [PATCH 31/60] style: fix import order --- .../main/java/com/diffplug/spotless/npm/ListableAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java index 3e05e8e51c..24ae62fde6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java @@ -15,13 +15,13 @@ */ package com.diffplug.spotless.npm; -import javax.annotation.Nonnull; - import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; +import javax.annotation.Nonnull; + class ListableAdapter implements Iterable { private final List delegate; From 7da08c7fbc5b8b908edd6bd36a2fd7272a7c4998 Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:25:08 -0400 Subject: [PATCH 32/60] fix: remove HasBuiltinDelimiterForLicense as it's not quite applicable --- plugin-gradle/README.md | 2 +- .../diffplug/gradle/spotless/FlexmarkExtension.java | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 91def5ad5f..a2a3ac948e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -62,7 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format)) - [Python](#python) ([black](#black)) - [FreshMark](#freshmark) aka markdown - - [FlexMark](#flexmark) aka markdown + - [Flexmark](#flexmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java index feee2c4801..047b0eda73 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java @@ -22,7 +22,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.markdown.FlexmarkStep; -public class FlexmarkExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { +public class FlexmarkExtension extends FormatExtension { static final String NAME = "flexmark"; @Inject @@ -30,16 +30,6 @@ public FlexmarkExtension(SpotlessExtension spotless) { super(spotless); } - @Override - public LicenseHeaderConfig licenseHeader(String licenseHeader) { - return licenseHeader(licenseHeader, null); - } - - @Override - public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { - return licenseHeaderFile(licenseHeaderFile, null); - } - public FlexmarkFormatterConfig flexmarkFormatter() { return flexmarkFormatter(FlexmarkStep.defaultVersion()); } From 0948c3e2323895efc7d6574d5e20f9ce358d8708 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Sep 2023 16:12:10 +0800 Subject: [PATCH 33/60] Support ktlint 1.0.0 https://github.com/pinterest/ktlint/releases/tag/1.0.0 --- lib/build.gradle | 7 +- .../compat/KtLintCompat1Dot0Dot0Adapter.java | 165 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 36 ++-- .../diffplug/spotless/kotlin/KtLintStep.java | 9 +- .../KtLintCompat1Dot0Dot0AdapterTest.java | 71 ++++++++ .../resources/EmptyClassBody.kt | 3 + .../resources/FailsNoSemicolons.kt | 3 + plugin-gradle/README.md | 2 +- .../spotless/maven/kotlin/KtlintTest.java | 10 +- .../spotless/kotlin/KtLintStepTest.java | 10 ++ 10 files changed, 293 insertions(+), 23 deletions(-) create mode 100644 lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt diff --git a/lib/build.gradle b/lib/build.gradle index 01591e557d..0288277c78 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -48,6 +48,7 @@ versionCompatibility { '0.48.0', '0.49.0', '0.50.0', + '1.0.0', ] targetSourceSetName = 'ktlint' } @@ -104,10 +105,14 @@ dependencies { compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' - // ktlint latest supported version + // ktlint previous supported version compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.50.0' compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.50.0' compatKtLint0Dot50Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' + // ktlint latest supported version + compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:1.0.0' + compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:1.0.0' + compatKtLint1Dot0Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' // palantirJavaFormat palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // scalafmt diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java new file mode 100644 index 0000000000..7b12169400 --- /dev/null +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -0,0 +1,165 @@ +/* + * 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.glue.ktlint.compat; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; +import com.pinterest.ktlint.rule.engine.api.Code; +import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; +import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; +import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; +import com.pinterest.ktlint.rule.engine.api.LintError; +import com.pinterest.ktlint.rule.engine.core.api.Rule; +import com.pinterest.ktlint.rule.engine.core.api.RuleId; +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; +import com.pinterest.ktlint.rule.engine.core.api.RuleSetId; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter { + + private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class); + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } + + static class FormatterCallback implements Function2 { + + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId().getValue(), lint.getDetail()); + } + return Unit.INSTANCE; + } + } + + @Override + public String format(final String text, Path path, final boolean isScript, + Path editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect(Collectors.toList()), + editorConfigOverrideMap); + } + EditorConfigDefaults editorConfig; + if (editorConfigPath == null || !Files.exists(editorConfigPath)) { + editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + } else { + editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, Collections.emptySet()); + } + + return new KtLintRuleEngine( + allRuleProviders, + editorConfig, + editorConfigOverride, + false, + path.getFileSystem()) + .format(Code.Companion.fromPath(path), formatterCallback); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + + if (property == null && entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to RuleSetId + RuleSetId id = new RuleSetId(parts[0]); + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled); + } else { + // convert ktlint_{ruleset}_{rulename} to RuleId + RuleId id = new RuleId(parts[0] + ":" + parts[1]); + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled); + } + } + + if (property == null) { + return null; + } else { + return new Pair<>(property, entry.getValue()); + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 1a11e8bcce..7ae0222566 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -33,22 +33,28 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData, Map editorConfigOverrideMap) { - int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 50) { - // Fixed `RuleId` and `RuleSetId` issues - // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing - // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point - this.adapter = new KtLintCompat0Dot50Dot0Adapter(); - } else if (minorVersion == 49) { - // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) - // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property - // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 - this.adapter = new KtLintCompat0Dot49Dot0Adapter(); - } else if (minorVersion == 48) { - // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + String[] versions = version.split("\\."); + int majorVersion = Integer.parseInt(versions[0]); + int minorVersion = Integer.parseInt(versions[1]); + if (majorVersion == 1) { + this.adapter = new KtLintCompat1Dot0Dot0Adapter(); } else { - throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); + if (minorVersion >= 50) { + // Fixed `RuleId` and `RuleSetId` issues + // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing + // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point + this.adapter = new KtLintCompat0Dot50Dot0Adapter(); + } else if (minorVersion == 49) { + // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) + // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property + // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 + this.adapter = new KtLintCompat0Dot49Dot0Adapter(); + } else if (minorVersion == 48) { + // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + } else { + throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); + } } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 8f3fde5731..d08c59b839 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,10 +36,10 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.50.0"; + private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; - static final String PACKAGE = "com.pinterest"; - static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; + static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; + static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); @@ -110,7 +110,8 @@ static final class State implements Serializable { this.version = version; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, + provisioner); this.editorConfigPath = editorConfigPath; this.isScript = isScript; } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java new file mode 100644 index 0000000000..5ed2517c6f --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -0,0 +1,71 @@ +/* + * 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.glue.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat1Dot0Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); + String text = loadAndWriteText(path, "EmptyClassBody.kt"); + final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + assertEquals("class EmptyClassBody\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); + String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat1Dot0Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt new file mode 100644 index 0000000000..7da53fb78d --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt @@ -0,0 +1,3 @@ +class EmptyClassBody { + +} diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt new file mode 100644 index 0000000000..4cf05ceacf --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt @@ -0,0 +1,3 @@ +class FailsNoSemicolons { + val i = 0; +} diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 944c07bb6e..9cc5019f57 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -399,7 +399,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. spotless { kotlin { // version, userData and editorConfigOverride are all optional - ktlint("0.50.0") + ktlint("1.0.0") .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride(mapOf("indent_size" to 2)) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index ba6f1d8e2c..f3f360dc5d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * 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. @@ -32,7 +32,13 @@ void testKtlint() throws Exception { @Test void testKtlintEditorConfigOverride() throws Exception { - writePomWithKotlinSteps("truetrue"); + writePomWithKotlinSteps("\n" + + " \n" + + " true\n" + + " true\n" + + " intellij_idea\n" + + " \n" + + ""); String path = "src/main/kotlin/Main.kt"; setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 5b62eeed48..0ccb47d1ed 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -74,6 +74,16 @@ void works0_50_0() { "Wildcard import"); } + @Test + void works1_0_0() { + FormatterStep step = KtLintStep.create("1.0.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: standard:no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void behavior() { FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); From 0224d3575f35e537f2cbc93e0903b984df389f44 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 10 Sep 2023 02:00:45 +0800 Subject: [PATCH 34/60] Update changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 +++ plugin-gradle/README.md | 7 ++++++- plugin-maven/CHANGES.md | 3 +++ plugin-maven/README.md | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1d78e8d932..c2d379a874 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.41.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eab7e32b2d..b66fcbc262 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). + The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9cc5019f57..9a4b84c4dd 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -402,7 +402,12 @@ spotless { ktlint("1.0.0") .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement - .editorConfigOverride(mapOf("indent_size" to 2)) + .editorConfigOverride( + mapOf( + "indent_size" to 2, + "ktlint_code_style" to "intellij_idea", + ) + ) } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f932806fcc..54f92898a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). +The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. ## [2.39.0] - 2023-08-29 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 74872ef61f..9419490d3e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -409,10 +409,11 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 0.43.2 + 1.0.0 true true + intellij_idea ``` From f32701212bf8d327c67d10c35316cb80dcdf577b Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 10 Sep 2023 19:58:18 +0800 Subject: [PATCH 35/60] Migrate deprecated buildDir usages https://docs.gradle.org/8.3/userguide/upgrading_version_8.html#project_builddir --- plugin-gradle/README.md | 2 +- .../com/diffplug/gradle/spotless/FormatExtension.java | 8 ++++---- .../com/diffplug/gradle/spotless/JavascriptExtension.java | 2 +- .../gradle/spotless/RegisterDependenciesTask.java | 2 +- .../diffplug/gradle/spotless/SpotlessDiagnoseTask.java | 5 +++-- .../java/com/diffplug/gradle/spotless/SpotlessTask.java | 2 +- .../com/diffplug/gradle/spotless/TypescriptExtension.java | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index fcdcfc213a..f81b897a4a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1243,7 +1243,7 @@ To use a fixed binary, omit the `version` and specify a `pathToExe`: spotless { format 'rome', { target '**/*.js','**/*.ts','**/*.json' - rome().pathToExe("${project.buildDir.absolutePath}/bin/rome") + rome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/rome") } } ``` 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 7a62f8cabf..1f8b0c95b2 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 @@ -280,9 +280,9 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu excludes.add(".gradle"); } // no build folders (flatInclude means that subproject might not be subfolders, see https://github.com/diffplug/spotless/issues/121) - relativizeIfSubdir(excludes, dir, getProject().getBuildDir()); + relativizeIfSubdir(excludes, dir, getProject().getLayout().getBuildDirectory().getAsFile().get()); for (Project subproject : getProject().getSubprojects()) { - relativizeIfSubdir(excludes, dir, subproject.getBuildDir()); + relativizeIfSubdir(excludes, dir, subproject.getLayout().getBuildDirectory().getAsFile().get()); } matchedFiles.exclude(excludes); } @@ -606,7 +606,7 @@ public T npmInstallCache(final Object npmInstallCache) { } public T npmInstallCache() { - this.npmInstallCache = new File(project.getBuildDir(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); + this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); replaceStep(); return (T) this; } @@ -673,7 +673,7 @@ protected FormatterStep createStep() { devDependencies, provisioner(), project.getProjectDir(), - project.getBuildDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( 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 76ad5650ca..cd2682e971 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 @@ -107,7 +107,7 @@ public FormatterStep createStep() { devDependencies, provisioner(), project.getProjectDir(), - project.getBuildDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java index bdeb9d7d94..b7ffd0a295 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java @@ -68,7 +68,7 @@ void setup() { taskService = buildServices.registerIfAbsent("SpotlessTaskService" + compositeBuildSuffix, SpotlessTaskService.class, spec -> {}); usesService(taskService); getBuildEventsListenerRegistry().onTaskCompletion(taskService); - unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies"); + unitOutput = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "tmp/spotless-register-dependencies"); } List steps = new ArrayList<>(); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java index f20957e650..6dcba72864 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * 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. @@ -43,7 +43,8 @@ public SpotlessTask getSource() { @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") public void performAction() throws IOException { Path srcRoot = getProject().getProjectDir().toPath(); - Path diagnoseRoot = getProject().getBuildDir().toPath().resolve("spotless-diagnose-" + source.formatName()); + Path diagnoseRoot = getProject().getLayout().getBuildDirectory().getAsFile().get() + .toPath().resolve("spotless-diagnose-" + source.formatName()); getProject().delete(diagnoseRoot.toFile()); try (Formatter formatter = source.buildFormatter()) { for (File file : source.target) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java index 2af9a80b7a..7b225eacd0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java @@ -148,7 +148,7 @@ public void setTarget(Iterable target) { } } - protected File outputDirectory = new File(getProject().getBuildDir(), "spotless/" + getName()); + protected File outputDirectory = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "spotless/" + getName()); @OutputDirectory public File getOutputDirectory() { 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 ddb7fbfc10..929ea4423b 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 @@ -118,7 +118,7 @@ public FormatterStep createStep() { devDependencies, provisioner(), project.getProjectDir(), - project.getBuildDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), typedConfigFile(), @@ -215,7 +215,7 @@ public FormatterStep createStep() { devDependencies, provisioner(), project.getProjectDir(), - project.getBuildDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); From 49a64c43601f047c817f3d85ad132948d9bd799a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 10 Sep 2023 17:33:25 +0000 Subject: [PATCH 36/60] chore(deps): update plugin com.github.spotbugs to v5.1.3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index a24c6d24d5..11ac98ec93 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ plugins { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.14' apply false + id 'com.github.spotbugs' version '5.1.3' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.2' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md From c3f286224947ae53a94d6618a877c564866852e6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 13 Sep 2023 22:31:29 -0700 Subject: [PATCH 37/60] Move the changelog entries to the right place. --- CHANGES.md | 4 ++-- plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 52db59e7bd..2112f3aa2c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +### Added +* Added support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) @@ -18,7 +19,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756)) * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ca1fd168e..e4360b02bb 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] - +### Added +* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) @@ -11,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e8e4081019..3bcc396f8d 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,7 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +### Added +* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) @@ -11,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From 919b4811448e1ec11ceadfebc8bcfc8f48137ad4 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 15 Sep 2023 13:41:57 +0800 Subject: [PATCH 38/60] Fix ktlint tests --- .../com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 10 +++++++++- .../gradle/spotless/KotlinExtensionTest.java | 1 + .../gradle/spotless/KotlinGradleExtensionTest.java | 1 + .../java/com/diffplug/spotless/TestProvisioner.java | 12 ++++++++++-- .../com/diffplug/spotless/kotlin/KtLintStepTest.java | 8 ++++---- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index d08c59b839..bedbb4a071 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -39,7 +39,7 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index e1129b3b0b..a92d583596 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -34,6 +34,7 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.kotlin.KtLintStep; /** Should be package-private. */ class GradleProvisioner { @@ -121,7 +122,14 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setCanBeConsumed(false); config.setVisible(false); config.attributes(attr -> { - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + final String type; + // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. + if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { + type = Bundling.SHADOWED; + } else { + type = Bundling.EXTERNAL; + } + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); }); return config.resolve(); } catch (Exception e) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 1c23728244..a2fa7c16e7 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -73,6 +73,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlin {", " ktlint().editorConfigOverride([", + " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 7dade5f2ff..6d7bdf351a 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -52,6 +52,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlinGradle {", " ktlint().editorConfigOverride([", + " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 0d9ced4c9e..6a942d8ca3 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * 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. @@ -39,6 +39,7 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; +import com.diffplug.spotless.kotlin.KtLintStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -70,7 +71,14 @@ private static Provisioner createWithRepositories(Consumer re config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); config.attributes(attr -> { - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + final String type; + // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. + if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { + type = Bundling.SHADOWED; + } else { + type = Bundling.EXTERNAL; + } + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); }); try { return config.resolve(); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 0ccb47d1ed..02526b46e6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -80,8 +80,8 @@ void works1_0_0() { StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: standard:no-wildcard-imports\n" + - "Wildcard import"); + "rule: standard:no-empty-file\n" + + "File 'unsolvable.dirty' should not be empty"); } @Test @@ -90,8 +90,8 @@ void behavior() { StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: standard:no-wildcard-imports\n" + - "Wildcard import"); + "rule: standard:no-empty-file\n" + + "File 'unsolvable.dirty' should not be empty"); } @Test From a333813a787b38a604683a92e566a54c1051d34e Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Fri, 15 Sep 2023 19:45:54 +0100 Subject: [PATCH 39/60] Add support for biome, #1804 --- .../diffplug/spotless/rome/EBiomeFlavor.java | 80 +++ .../rome/RomeExecutableDownloader.java | 101 ++- .../com/diffplug/spotless/rome/RomeStep.java | 174 ++--- .../gradle/spotless/FormatExtension.java | 368 +++++++--- .../gradle/spotless/JavascriptExtension.java | 86 ++- .../gradle/spotless/JsonExtension.java | 61 +- .../gradle/spotless/RomeStepConfig.java | 100 +-- .../gradle/spotless/TypescriptExtension.java | 104 ++- .../gradle/spotless/BiomeIntegrationTest.java | 343 +++++++++ .../gradle/spotless/RomeIntegrationTest.java | 4 +- .../spotless/maven/generic/Biome.java | 60 ++ .../spotless/maven/generic/Format.java | 14 + .../diffplug/spotless/maven/generic/Rome.java | 10 +- .../spotless/maven/javascript/BiomeJs.java | 33 + .../spotless/maven/javascript/Javascript.java | 5 + .../spotless/maven/javascript/RomeJs.java | 7 + .../spotless/maven/json/BiomeJson.java | 33 + .../diffplug/spotless/maven/json/Json.java | 5 + .../spotless/maven/json/RomeJson.java | 7 + .../spotless/maven/rome/AbstractRome.java | 68 +- .../spotless/maven/typescript/BiomeTs.java | 33 + .../spotless/maven/typescript/RomeTs.java | 7 + .../spotless/maven/typescript/Typescript.java | 5 + .../maven/MavenIntegrationHarness.java | 5 + .../spotless/maven/biome/BiomeMavenTest.java | 202 ++++++ .../spotless/maven/rome/RomeMavenTest.java | 3 +- .../biome/config/line-width-120.json | 11 + .../resources/biome/config/line-width-80.json | 11 + .../src/main/resources/biome/js/fileAfter.cjs | 3 + .../src/main/resources/biome/js/fileAfter.js | 3 + .../src/main/resources/biome/js/fileAfter.jsx | 3 + .../src/main/resources/biome/js/fileAfter.mjs | 3 + .../main/resources/biome/js/fileBefore.cjs | 3 + .../src/main/resources/biome/js/fileBefore.js | 3 + .../main/resources/biome/js/fileBefore.jsx | 4 + .../main/resources/biome/js/fileBefore.mjs | 3 + .../resources/biome/js/longLineAfter120.js | 1 + .../resources/biome/js/longLineAfter80.js | 13 + .../main/resources/biome/js/longLineBefore.js | 1 + .../main/resources/biome/json/fileAfter.json | 5 + .../main/resources/biome/json/fileBefore.json | 7 + .../src/main/resources/biome/ts/fileAfter.cts | 4 + .../src/main/resources/biome/ts/fileAfter.mts | 4 + .../src/main/resources/biome/ts/fileAfter.ts | 4 + .../src/main/resources/biome/ts/fileAfter.tsx | 7 + .../main/resources/biome/ts/fileBefore.cts | 4 + .../main/resources/biome/ts/fileBefore.mts | 5 + .../src/main/resources/biome/ts/fileBefore.ts | 5 + .../main/resources/biome/ts/fileBefore.tsx | 8 + .../diffplug/spotless/rome/RomeStepTest.java | 657 ++++++++++++------ 50 files changed, 2114 insertions(+), 576 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java create mode 100644 testlib/src/main/resources/biome/config/line-width-120.json create mode 100644 testlib/src/main/resources/biome/config/line-width-80.json create mode 100644 testlib/src/main/resources/biome/js/fileAfter.cjs create mode 100644 testlib/src/main/resources/biome/js/fileAfter.js create mode 100644 testlib/src/main/resources/biome/js/fileAfter.jsx create mode 100644 testlib/src/main/resources/biome/js/fileAfter.mjs create mode 100644 testlib/src/main/resources/biome/js/fileBefore.cjs create mode 100644 testlib/src/main/resources/biome/js/fileBefore.js create mode 100644 testlib/src/main/resources/biome/js/fileBefore.jsx create mode 100644 testlib/src/main/resources/biome/js/fileBefore.mjs create mode 100644 testlib/src/main/resources/biome/js/longLineAfter120.js create mode 100644 testlib/src/main/resources/biome/js/longLineAfter80.js create mode 100644 testlib/src/main/resources/biome/js/longLineBefore.js create mode 100644 testlib/src/main/resources/biome/json/fileAfter.json create mode 100644 testlib/src/main/resources/biome/json/fileBefore.json create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.cts create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.mts create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.ts create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.tsx create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.cts create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.mts create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.ts create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.tsx diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java new file mode 100644 index 0000000000..e47662f154 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java @@ -0,0 +1,80 @@ +package com.diffplug.spotless.rome; + +/** + * The flavor of Biome to use. Exists for compatibility reason, may be removed + * shortly. + *

+ * Will be removed once the old Rome project is not supported anymore. + */ +public enum EBiomeFlavor { + /** 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"); + + private final String configName; + private final String defaultVersion; + private final String downloadFilePattern; + private final String shortName; + private final String urlPattern; + + EBiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, + String urlPattern) { + this.shortName = shortName; + this.defaultVersion = defaultVersion; + this.configName = configName; + this.downloadFilePattern = downloadFilePattern; + this.urlPattern = urlPattern; + } + + /** + * @return The name of the default config file. + */ + public String configName() { + return configName; + } + + /** + * @return Default version to use when no version was set explicitly. + */ + public String defaultVersion() { + return defaultVersion; + } + + /** + * @return The pattern for {@link String#format(String, Object...) + * String.format()} for the file name of a Biome executable for a + * certain version and architecure. The first parameter is the platform, + * the second is the OS, the third is the architecture. + */ + public String getDownloadFilePattern() { + return downloadFilePattern; + } + + /** + * @return The pattern for {@link String#format(String, Object...) + * String.format()} for the URL where the executables can be downloaded. + * The first parameter is the version, the second parameter is the OS / + * platform. + */ + public String getUrlPattern() { + return urlPattern; + } + + /** + * @return The short name of this flavor, i.e. rome or + * biome. + */ + public String shortName() { + return shortName; + } +} \ No newline at end of file diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 578916a54b..7ff0bdb622 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory; /** - * Downloader for the Rome executable: - * https://github.com/rome/tools. + * Downloader for the Biome executable: + * https://github.com/biomejs/biome. */ final class RomeExecutableDownloader { private static final Logger logger = LoggerFactory.getLogger(RomeExecutableDownloader.class); @@ -51,15 +51,7 @@ final class RomeExecutableDownloader { /** * The pattern for {@link String#format(String, Object...) String.format()} for - * the file name of a Rome executable for a certain version and architecure. The - * first parameter is the platform, the second is the OS, the third is the - * architecture. - */ - private static final String DOWNLOAD_FILE_PATTERN = "rome-%s-%s-%s"; - - /** - * The pattern for {@link String#format(String, Object...) String.format()} for - * the platform part of the Rome executable download URL. First parameter is the + * the platform part of the Biome executable download URL. First parameter is the * OS, second parameter the architecture, the third the file extension. */ private static final String PLATFORM_PATTERN = "%s-%s%s"; @@ -70,13 +62,6 @@ final class RomeExecutableDownloader { */ private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ}; - /** - * The pattern for {@link String#format(String, Object...) String.format()} for - * the URL where the Rome executables can be downloaded. The first parameter is - * the version, the second parameter is the OS / platform. - */ - private static final String URL_PATTERN = "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s"; - /** * {@link OpenOption Open options} for creating a new file, overwriting the * existing file if present. @@ -84,25 +69,29 @@ final class RomeExecutableDownloader { private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE}; - private Path downloadDir; + private final Path downloadDir; + + private final EBiomeFlavor flavor; /** - * Creates a new downloader for the Rome executable. The executable files are + * Creates a new downloader for the Biome executable. The executable files are * stored in the given download directory. * - * @param downloadDir Directory where + * @param flavor Flavor of Biome to use. + * @param downloadDir Directory where to store the downloaded executable. */ - public RomeExecutableDownloader(Path downloadDir) { + public RomeExecutableDownloader(EBiomeFlavor flavor, Path downloadDir) { + this.flavor = flavor; this.downloadDir = downloadDir; } /** - * Downloads the Rome executable for the current platform from the network to + * Downloads the Biome executable for the current platform from the network to * the download directory. When the executable exists already, it is * overwritten. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable cannot be downloaded from * the network or the file system could not be * accessed. @@ -121,7 +110,7 @@ public Path download(String version) throws IOException, InterruptedException { if (executableDir != null) { Files.createDirectories(executableDir); } - logger.info("Attempting to download Rome from '{}' to '{}'", url, executablePath); + logger.info("Attempting to download Biome from '{}' to '{}'", url, executablePath); var request = HttpRequest.newBuilder(URI.create(url)).GET().build(); var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS); var response = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build().send(request, handler); @@ -133,19 +122,19 @@ public Path download(String version) throws IOException, InterruptedException { throw new IOException("Failed to download file from " + url + ", file is empty or does not exist"); } writeChecksumFile(downloadedFile, checksumPath); - logger.debug("Rome was downloaded successfully to '{}'", downloadedFile); + logger.debug("Biome was downloaded successfully to '{}'", downloadedFile); return downloadedFile; } /** - * Ensures that the Rome executable for the current platform exists in the + * Ensures that the Biome executable for the current platform exists in the * download directory. When the executable does not exist in the download - * directory, an attempt is made to download the Rome executable from the + * directory, an attempt is made to download the Biome executable from the * network. When the executable exists already, no attempt to download it again * is made. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable cannot be downloaded from * the network or the file system could not be * accessed. @@ -157,23 +146,23 @@ public Path download(String version) throws IOException, InterruptedException { */ public Path ensureDownloaded(String version) throws IOException, InterruptedException { var platform = Platform.guess(); - logger.debug("Ensuring that Rome for platform '{}' is downloaded", platform); + logger.debug("Ensuring that Biome for platform '{}' is downloaded", platform); var existing = findDownloaded(version); if (existing.isPresent()) { - logger.debug("Rome was already downloaded, using executable at '{}'", existing.get()); + logger.debug("Biome was already downloaded, using executable at '{}'", existing.get()); return existing.get(); } else { - logger.debug("Rome was not yet downloaded, attempting to download executable"); + logger.debug("Biome was not yet downloaded, attempting to download executable"); return download(version); } } /** - * Attempts to find the Rome executable for the current platform in the download + * Attempts to find the Biome executable for the current platform in the download * directory. No attempt is made to download the executable from the network. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable does not exists in the * download directory, or when the file system * could not be accessed. @@ -184,7 +173,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce public Optional findDownloaded(String version) throws IOException { var platform = Platform.guess(); var executablePath = getExecutablePath(version, platform); - logger.debug("Checking rome executable at {}", executablePath); + logger.debug("Checking Biome executable at {}", executablePath); return checkFileWithChecksum(executablePath) ? Optional.ofNullable(executablePath) : Optional.empty(); } @@ -248,12 +237,12 @@ private String computeChecksum(Path file, String algorithm) throws IOException { } /** - * Finds the code name for the given operating system used by the Rome + * Finds the code name for the given operating system used by the Biome * executable download URL. * * @param os Desired operating system. - * @return Code name for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Code name for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getArchitectureCodeName(Architecture architecture) throws IOException { switch (architecture) { @@ -281,28 +270,28 @@ private Path getChecksumPath(Path file) { } /** - * Finds the URL from which the Rome executable can be downloaded. + * Finds the URL from which the Biome executable can be downloaded. * - * @param version Desired Rome version. + * @param version Desired Biome version. * @param platform Desired platform. - * @return The URL for the Rome executable. - * @throws IOException When the platform is not supported by Rome. + * @return The URL for the Biome executable. + * @throws IOException When the platform is not supported by Biome. */ private String getDownloadUrl(String version, Platform platform) throws IOException { var osCodeName = getOsCodeName(platform.getOs()); var architectureCodeName = getArchitectureCodeName(platform.getArchitecture()); var extension = getDownloadUrlExtension(platform.getOs()); var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension); - return String.format(URL_PATTERN, version, platformString); + return String.format(flavor.getUrlPattern(), version, platformString); } /** - * Finds the file extension of the Rome download URL for the given operating + * Finds the file extension of the Biome download URL for the given operating * system. * * @param os Desired operating system. - * @return Extension for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Extension for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getDownloadUrlExtension(OS os) throws IOException { switch (os) { @@ -318,27 +307,27 @@ private String getDownloadUrlExtension(OS os) throws IOException { } /** - * Finds the path on the file system for the Rome executable with a given + * Finds the path on the file system for the Biome executable with a given * version and platform. * - * @param version Desired Rome version. + * @param version Desired Biome version. * @param platform Desired platform. - * @return The path for the Rome executable. + * @return The path for the Biome executable. */ private Path getExecutablePath(String version, Platform platform) { var os = platform.getOs().name().toLowerCase(Locale.ROOT); var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT); - var fileName = String.format(DOWNLOAD_FILE_PATTERN, os, arch, version); + var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version); return downloadDir.resolve(fileName); } /** - * Finds the code name for the given operating system used by the Rome + * Finds the code name for the given operating system used by the Biome * executable download URL. * * @param os Desired operating system. - * @return Code name for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Code name for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getOsCodeName(OS os) throws IOException { switch (os) { diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index d6a3e62669..88c35c8662 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -38,16 +38,16 @@ import com.diffplug.spotless.ProcessRunner; /** - * formatter step that formats JavaScript and TypeScript code with Rome: - * https://github.com/rome/tools. - * It delegates to the Rome executable. The Rome executable is downloaded from + * 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 * the network when no executable path is provided explicitly. */ public class RomeStep { private static final Logger logger = LoggerFactory.getLogger(RomeStep.class); /** - * Path to the directory with the {@code rome.json} config file, can be + * Path to the directory with the {@code biome.json} config file, can be * null, in which case the defaults are used. */ private String configPath; @@ -55,7 +55,7 @@ public class RomeStep { /** * 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: + * Currently the following languages are supported by Biome: *

    *
  • js (JavaScript)
  • *
  • jsx (JavaScript + JSX)
  • @@ -71,7 +71,13 @@ public class RomeStep { private String language; /** - * Path to the Rome executable. Can be null, but either a path to + * Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project. + */ + @Deprecated + private final EBiomeFlavor flavor; + + /** + * Path to the Biome executable. Can be null, but either a path to * the executable of a download directory and version must be given. The path * must be either an absolute path, or a file name without path separators. If * the latter, it is interpreted as a command in the user's path. @@ -79,46 +85,48 @@ public class RomeStep { private final String pathToExe; /** - * Absolute path to the download directory for storing the download Rome + * Absolute path to the download directory for storing the download Biome * executable. Can be null, but either a path to the executable of * a download directory and version must be given. */ private final String downloadDir; /** - * Version of Rome to download. Can be null, but either a path to + * Version of Biome to download. Can be null, but either a path to * the executable of a download directory and version must be given. */ private final String version; /** - * @return The name of this format step, i.e. {@code rome}. + * @return The name of this format step, i.e. biome or rome. */ - public static String name() { - return "rome"; + public String name() { + return flavor.shortName(); } /** - * Creates a Rome step that format code by downloading to the given Rome + * Creates a Biome step that format code by downloading to the given Biome * version. The executable is downloaded from the network. * - * @param version Version of the Rome executable to download. + * @param flavor Flavor of Biome to use. + * @param version Version of the Biome executable to download. * @param downloadDir Directory where to place the downloaded executable. - * @return A new Rome step that download the executable from the network. + * @return A new Biome step that download the executable from the network. */ - public static RomeStep withExeDownload(String version, String downloadDir) { - return new RomeStep(version, null, downloadDir); + public static RomeStep withExeDownload(EBiomeFlavor flavor, String version, String downloadDir) { + return new RomeStep(flavor, version, null, downloadDir); } /** - * Creates a Rome step that formats code by delegating to the Rome executable + * Creates a Biome step that formats code by delegating to the Biome executable * located at the given path. * - * @param pathToExe Path to the Rome executable to use. - * @return A new Rome step that format with the given executable. + * @param flavor Flavor of Biome to use. + * @param pathToExe Path to the Biome executable to use. + * @return A new Biome step that format with the given executable. */ - public static RomeStep withExePath(String pathToExe) { - return new RomeStep(null, pathToExe, null); + public static RomeStep withExePath(EBiomeFlavor flavor, String pathToExe) { + return new RomeStep(flavor, null, pathToExe, null); } /** @@ -140,21 +148,21 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p } /** - * Finds the default version for Rome when no version is specified explicitly. + * Finds the default version for Biome when no version is specified explicitly. * Over time this will become outdated -- people should always specify the * version explicitly! * - * @return The default version for Rome. + * @return The default version for Biome. */ - private static String defaultVersion() { - return "12.0.0"; + private static String defaultVersion(EBiomeFlavor flavor) { + return flavor.defaultVersion(); } /** * Attempts to make the given file executable. This is a best-effort attempt, * any errors are swallowed. Depending on the OS, the file might still be * executable even if this method fails. The user will get a descriptive error - * later when we attempt to execute the Rome executable. + * later when we attempt to execute the Biome executable. * * @param filePath Path to the file to make executable. */ @@ -187,60 +195,64 @@ private static String resolveNameAgainstPath(String name) throws IOException, In } /** - * Checks the Rome config path. When the config path does not exist or when it - * does not contain a file named {@code rome.json}, an error is thrown. + * Checks the Biome config path. When the config path does not exist or when it + * does not contain a file named {@code biome.json}, an error is thrown. */ - private static void validateRomeConfigPath(String configPath) { + private static void validateBiomeConfigPath(EBiomeFlavor flavor, String configPath) { if (configPath == null) { return; } var path = Paths.get(configPath); - var config = path.resolve("rome.json"); + var config = path.resolve(flavor.configName()); if (!Files.exists(path)) { - throw new IllegalArgumentException("Rome config directory does not exist: " + path); + throw new IllegalArgumentException("Biome config directory does not exist: " + path); } if (!Files.exists(config)) { - throw new IllegalArgumentException("Rome config does not exist: " + config); + throw new IllegalArgumentException("Biome config does not exist: " + config); } } /** - * Checks the Rome executable file. When the file does not exist, an error is + * Checks the Biome executable file. When the file does not exist, an error is * thrown. */ - private static void validateRomeExecutable(String resolvedPathToExe) { + private static void validateBiomeExecutable(String resolvedPathToExe) { if (!new File(resolvedPathToExe).isFile()) { - throw new IllegalArgumentException("Rome executable does not exist: " + resolvedPathToExe); + throw new IllegalArgumentException("Biome executable does not exist: " + resolvedPathToExe); } } /** - * Creates a new Rome step with the configuration from the given builder. + * Creates a new Biome step with the configuration from the given builder. * - * @param builder Builder with the configuration to use. + * @param flavor Flavor of Biome to use. + * @param version Version of the Biome executable to download. + * @param pathToExe Path to the Biome executable to use. + * @param downloadDir Directory where to place the downloaded executable. */ - private RomeStep(String version, String pathToExe, String downloadDir) { - this.version = version != null && !version.isBlank() ? version : defaultVersion(); + private RomeStep(EBiomeFlavor flavor, String version, String pathToExe, String downloadDir) { + this.flavor = flavor; + this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor); this.pathToExe = pathToExe; this.downloadDir = downloadDir; } /** * Creates a formatter step with the current configuration, which formats code - * by passing it to the Rome executable. + * by passing it to the Biome executable. * - * @return A new formatter step for formatting with Rome. + * @return A new formatter step for formatting with Biome. */ public FormatterStep create() { return FormatterStep.createLazy(name(), this::createState, State::toFunc); } /** - * Sets the path to the directory with the {@code rome.json} config file. When + * Sets the path to the directory with the {@code biome.json} config file. When * no config path is set, the default configuration is used. * - * @param configPath Config path to use. Must point to a directory which contain - * a file named {@code rome.json}. + * @param configPath Config path to use. Must point to a directory which contains + * a file named {@code biome.json}. * @return This builder instance for chaining method calls. */ public RomeStep withConfigPath(String configPath) { @@ -251,7 +263,7 @@ public RomeStep withConfigPath(String configPath) { /** * Sets the language of the files to format When no language is set, it is * determined automatically from the file name. The following languages are - * currently supported by Rome. + * currently supported by Biome. * *
      *
    • js (JavaScript)
    • @@ -274,41 +286,41 @@ public RomeStep withLanguage(String language) { } /** - * Resolves the Rome executable, possibly downloading it from the network, and + * Resolves the Biome executable, possibly downloading it from the network, and * creates a new state instance with the resolved executable that can format - * code via Rome. + * code via Biome. * - * @return The state instance for formatting code via Rome. + * @return The state instance for formatting code via Biome. * @throws IOException When any file system or network operations - * failed, such as when the Rome executable could + * failed, such as when the Biome executable could * not be downloaded, or when the given executable * does not exist. - * @throws InterruptedException When the Rome executable needs to be downloaded + * @throws InterruptedException When the Biome executable needs to be downloaded * and this thread was interrupted while waiting * for the download to complete. */ private State createState() throws IOException, InterruptedException { var resolvedPathToExe = resolveExe(); - validateRomeExecutable(resolvedPathToExe); - validateRomeConfigPath(configPath); - logger.debug("Using Rome executable located at '{}'", resolvedPathToExe); + validateBiomeExecutable(resolvedPathToExe); + validateBiomeConfigPath(flavor, configPath); + logger.debug("Using Biome executable located at '{}'", resolvedPathToExe); var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe))); makeExecutable(resolvedPathToExe); return new State(resolvedPathToExe, exeSignature, configPath, language); } /** - * Resolves the path to the Rome executable, given the configuration of this - * step. When the path to the Rome executable is given explicitly, that path is - * used as-is. Otherwise, at attempt is made to download the Rome executable for + * Resolves the path to the Biome executable, given the configuration of this + * step. When the path to the Biome executable is given explicitly, that path is + * used as-is. Otherwise, at attempt is made to download the Biome executable for * the configured version from the network, unless it was already downloaded and * is available in the cache. * - * @return The path to the resolved Rome executable. + * @return The path to the resolved Biome executable. * @throws IOException When any file system or network operations - * failed, such as when the Rome executable could + * failed, such as when the Biome executable could * not be downloaded. - * @throws InterruptedException When the Rome executable needs to be downloaded + * @throws InterruptedException When the Biome executable needs to be downloaded * and this thread was interrupted while waiting * for the download to complete. */ @@ -321,7 +333,7 @@ private String resolveExe() throws IOException, InterruptedException { return pathToExe; } } else { - var downloader = new RomeExecutableDownloader(Paths.get(downloadDir)); + var downloader = new RomeExecutableDownloader(flavor, Paths.get(downloadDir)); var downloaded = downloader.ensureDownloaded(version).toString(); makeExecutable(downloaded); return downloaded; @@ -329,7 +341,7 @@ private String resolveExe() throws IOException, InterruptedException { } /** - * The internal state used by the Rome formatter. A state instance is created + * The internal state used by the Biome formatter. A state instance is created * when the spotless plugin for Maven or Gradle is executed, and reused for all * formatting requests for different files. The lifetime of the instance ends * when the Maven or Gradle plugin was successfully executed. @@ -349,7 +361,7 @@ private static class State implements Serializable { private final FileSignature exeSignature; /** - * The optional path to the directory with the {@code rome.json} config file. + * The optional path to the directory with the {@code biome.json} config file. */ private final String configPath; @@ -360,12 +372,12 @@ private static class State implements Serializable { private final String language; /** - * Creates a new state for instance which can format code with the given Rome + * Creates a new state for instance which can format code with the given Biome * executable. * - * @param exe Path to the Rome executable. - * @param exeSignature Signature (e.g. SHA-256 checksum) of the Rome executable. - * @param configPath Path to the optional directory with the {@code rome.json} + * @param exe Path to the Biome executable. + * @param exeSignature Signature (e.g. SHA-256 checksum) of the Biome executable. + * @param configPath Path to the optional directory with the {@code biome.json} * config file, can be null, in which case the * defaults are used. */ @@ -377,13 +389,13 @@ private State(String exe, FileSignature exeSignature, String configPath, String } /** - * Builds the list of arguments for the command that executes Rome to format a + * Builds the list of arguments for the command that executes Biome to format a * piece of code passed via stdin. * * @param file File to format. - * @return The Rome command to use for formatting code. + * @return The Biome command to use for formatting code. */ - private String[] buildRomeCommand(File file) { + private String[] buildBiomeCommand(File file) { var fileName = resolveFileName(file); var argList = new ArrayList(); argList.add(pathToExe); @@ -398,37 +410,37 @@ private String[] buildRomeCommand(File file) { } /** - * Formats the given piece of code by delegating to the Rome executable. The - * code is passed to Rome via stdin, the file name is used by Rome only to + * Formats the given piece of code by delegating to the Biome executable. The + * code is passed to Biome via stdin, the file name is used by Biome only to * determine the code syntax (e.g. JavaScript or TypeScript). * - * @param runner Process runner for invoking the Rome executable. + * @param runner Process runner for invoking the Biome executable. * @param input Code to format. * @param file File to format. * @return The formatted code. * @throws IOException When a file system error occurred while - * executing Rome. + * executing Biome. * @throws InterruptedException When this thread was interrupted while waiting - * for Rome to finish formatting. + * for Biome to finish formatting. */ private String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { var stdin = input.getBytes(StandardCharsets.UTF_8); - var args = buildRomeCommand(file); + var args = buildBiomeCommand(file); if (logger.isDebugEnabled()) { - logger.debug("Running Rome comand to format code: '{}'", String.join(", ", args)); + logger.debug("Running Biome comand to format code: '{}'", String.join(", ", args)); } return runner.exec(stdin, args).assertExitZero(StandardCharsets.UTF_8); } /** - * The Rome executable currently does not have a parameter to specify the - * expected language / syntax. Rome always determined the language from the file + * The Biome executable currently does not have a parameter to specify the + * expected language / syntax. Biome always determined the language from the file * extension. This method returns the file name for the desired language when a * language was requested explicitly, or the file name of the input file for * auto detection. * * @param file File to be formatted. - * @return The file name to pass to the Rome executable. + * @return The file name to pass to the Biome executable. */ private String resolveFileName(File file) { var name = file.getName(); @@ -454,7 +466,7 @@ private String resolveFileName(File file) { return "tsx".equals(ext) ? name : "file.tsx"; case "json": return "json".equals(ext) ? name : "file.json"; - // so that we can support new languages such as css or yaml when Rome adds + // so that we can support new languages such as css or yaml when Biome adds // support for them without having to change the code default: return "file." + language; @@ -463,7 +475,7 @@ private String resolveFileName(File file) { /** * Creates a new formatter function for formatting a piece of code by delegating - * to the Rome executable. + * to the Biome executable. * * @return A formatter function for formatting code. */ 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 1f8b0c95b2..61fb0a6e5b 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 @@ -67,6 +67,7 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; import groovy.lang.Closure; @@ -95,29 +96,44 @@ private String formatName() { LineEnding lineEndings; - /** Returns the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ + /** + * Returns the line endings to use (defaults to + * {@link SpotlessExtensionImpl#getLineEndings()}. + */ public LineEnding getLineEndings() { return lineEndings == null ? spotless.getLineEndings() : lineEndings; } - /** Sets the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ + /** + * Sets the line endings to use (defaults to + * {@link SpotlessExtensionImpl#getLineEndings()}. + */ public void setLineEndings(LineEnding lineEndings) { this.lineEndings = requireNonNull(lineEndings); } Charset encoding; - /** Returns the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Returns the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public Charset getEncoding() { return encoding == null ? spotless.getEncoding() : encoding; } - /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Sets the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public void setEncoding(String name) { setEncoding(Charset.forName(requireNonNull(name))); } - /** Sentinel to distinguish between "don't ratchet this format" and "use spotless parent format". */ + /** + * Sentinel to distinguish between "don't ratchet this format" and "use spotless + * parent format". + */ private static final String RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL = " not set at format level "; private String ratchetFrom = RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL; @@ -128,8 +144,8 @@ public String getRatchetFrom() { } /** - * Allows you to override the value from the parent {@link SpotlessExtension#setRatchetFrom(String)} - * for this specific format. + * Allows you to override the value from the parent + * {@link SpotlessExtension#setRatchetFrom(String)} for this specific format. */ public void setRatchetFrom(String ratchetFrom) { this.ratchetFrom = ratchetFrom; @@ -140,7 +156,10 @@ public void ratchetFrom(String ratchetFrom) { setRatchetFrom(ratchetFrom); } - /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Sets the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public void setEncoding(Charset charset) { encoding = requireNonNull(charset); } @@ -157,7 +176,10 @@ public void ignoreErrorForPath(String relativePath) { exceptionPolicy.excludePath(requireNonNull(relativePath)); } - /** Sets encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}). */ + /** + * Sets encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}). + */ public void encoding(String charset) { setEncoding(charset); } @@ -180,31 +202,33 @@ protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { } /** - * Sets which files should be formatted. Files to be formatted = (target - targetExclude). + * Sets which files should be formatted. Files to be formatted = (target - + * targetExclude). * * When this method is called multiple times, only the last call has any effect. * - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). * - * If you pass any strings that start with "**\/*", this method will automatically filter out - * "build", ".gradle", and ".git" folders. + * If you pass any strings that start with "**\/*", this method will + * automatically filter out "build", ".gradle", and ".git" folders. */ public void target(Object... targets) { this.target = parseTargetsIsExclude(targets, false); } /** - * Sets which files will be excluded from formatting. Files to be formatted = (target - targetExclude). + * Sets which files will be excluded from formatting. Files to be formatted = + * (target - targetExclude). * * When this method is called multiple times, only the last call has any effect. * - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). */ public void targetExclude(Object... targets) { this.targetExclude = parseTargetsIsExclude(targets, true); @@ -244,10 +268,10 @@ private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude } /** - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). */ protected final FileCollection parseTarget(Object target) { return parseTargetIsExclude(target, false); @@ -264,7 +288,8 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu String targetString = (String) target; matchedFiles.include(targetString); - // since people are likely to do '**/*.md', we want to make sure to exclude folders + // since people are likely to do '**/*.md', we want to make sure to exclude + // folders // they don't want to format which will slow down the operation greatly // but we only want to do that if they are *including* - if they are specifying // what they want to exclude, we shouldn't filter at all @@ -279,7 +304,8 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu if (getProject() == getProject().getRootProject()) { excludes.add(".gradle"); } - // no build folders (flatInclude means that subproject might not be subfolders, see https://github.com/diffplug/spotless/issues/121) + // no build folders (flatInclude means that subproject might not be subfolders, + // see https://github.com/diffplug/spotless/issues/121) relativizeIfSubdir(excludes, dir, getProject().getLayout().getBuildDirectory().getAsFile().get()); for (Project subproject : getProject().getSubprojects()) { relativizeIfSubdir(excludes, dir, subproject.getLayout().getBuildDirectory().getAsFile().get()); @@ -300,8 +326,8 @@ private static void relativizeIfSubdir(List relativePaths, File root, Fi } /** - * Returns the relative path between root and dest, - * or null if dest is not a child of root. + * Returns the relative path between root and dest, or null if dest is not a + * child of root. */ static @Nullable String relativize(File root, File dest) { String rootPath = root.getAbsolutePath(); @@ -321,7 +347,8 @@ public void addStep(FormatterStep newStep) { requireNonNull(newStep); int existingIdx = getExistingStepIdx(newStep.getName()); if (existingIdx != -1) { - throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); + throw new GradleException( + "Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); } steps.add(newStep); } @@ -333,7 +360,10 @@ public void addStep(Function createStepFn) { addStep(newStep); } - /** Returns the index of the existing step with the given name, or -1 if no such step exists. */ + /** + * Returns the index of the existing step with the given name, or -1 if no such + * step exists. + */ protected int getExistingStepIdx(String stepName) { for (int i = 0; i < steps.size(); ++i) { if (steps.get(i).getName().equals(stepName)) { @@ -347,7 +377,8 @@ protected int getExistingStepIdx(String stepName) { protected void replaceStep(FormatterStep replacementStep) { int existingIdx = getExistingStepIdx(replacementStep.getName()); if (existingIdx == -1) { - throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + formatName() + "' because it hasn't been added yet."); + throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + + formatName() + "' because it hasn't been added yet."); } steps.set(existingIdx, replacementStep); } @@ -358,20 +389,21 @@ public void clearSteps() { } /** - * An optional performance optimization if you are using any of the {@code custom} - * methods. If you aren't explicitly calling {@code custom}, then this method - * has no effect. + * An optional performance optimization if you are using any of the + * {@code custom} methods. If you aren't explicitly calling {@code custom}, then + * this method has no effect. * - * Spotless tracks what files have changed from run to run, so that it can run faster - * by only checking files which have changed, or whose formatting steps have changed. - * If you use the {@code custom} methods, then gradle can never mark - * your files as {@code up-to-date}, because it can't know if perhaps the behavior of your - * custom function has changed. + * Spotless tracks what files have changed from run to run, so that it can run + * faster by only checking files which have changed, or whose formatting steps + * have changed. If you use the {@code custom} methods, then gradle can never + * mark your files as {@code up-to-date}, because it can't know if perhaps the + * behavior of your custom function has changed. * - * If you set {@code bumpThisNumberIfACustomStepChanges( )}, then spotless will - * assume that the custom rules have not changed if the number has not changed. If a - * custom rule does change, then you must bump the number so that spotless will know - * that it must recheck the files it has already checked. + * If you set {@code bumpThisNumberIfACustomStepChanges( )}, then + * spotless will assume that the custom rules have not changed if the number has + * not changed. If a custom rule does change, then you must bump the number so + * that spotless will know that it must recheck the files it has already + * checked. */ public void bumpThisNumberIfACustomStepChanges(int number) { globalState = number; @@ -389,13 +421,19 @@ protected Integer calculateState() throws Exception { } } - /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ + /** + * Adds a custom step. Receives a string with unix-newlines, must return a + * string with unix newlines. + */ public void custom(String name, Closure formatter) { requireNonNull(formatter, "formatter"); custom(name, formatter::call); } - /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ + /** + * Adds a custom step. Receives a string with unix-newlines, must return a + * string with unix newlines. + */ public void custom(String name, FormatterFunc formatter) { requireNonNull(formatter, "formatter"); addStep(FormatterStep.createLazy(name, () -> globalState, unusedState -> formatter)); @@ -447,9 +485,11 @@ public void nativeCmd(String name, String pathToExe, List arguments) { } /** - * Created by {@link FormatExtension#licenseHeader(String, String)} or {@link FormatExtension#licenseHeaderFile(Object, String)}. - * For most language-specific formats (e.g. java, scala, etc.) you can omit the second {@code delimiter} argument, because it is supplied - * automatically ({@link HasBuiltinDelimiterForLicense}). + * Created by {@link FormatExtension#licenseHeader(String, String)} or + * {@link FormatExtension#licenseHeaderFile(Object, String)}. For most + * language-specific formats (e.g. java, scala, etc.) you can omit the second + * {@code delimiter} argument, because it is supplied automatically + * ({@link HasBuiltinDelimiterForLicense}). */ public class LicenseHeaderConfig { LicenseHeaderStep builder; @@ -478,8 +518,8 @@ public LicenseHeaderConfig(LicenseHeaderStep builder) { } /** - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param delimiter Spotless will look for a line that starts with this regular + * expression pattern to know what the "top" is. */ public LicenseHeaderConfig delimiter(String delimiter) { builder = builder.withDelimiter(delimiter); @@ -488,8 +528,8 @@ public LicenseHeaderConfig delimiter(String delimiter) { } /** - * @param yearSeparator - * The characters used to separate the first and last years in multi years patterns. + * @param yearSeparator The characters used to separate the first and last years + * in multi years patterns. */ public LicenseHeaderConfig yearSeparator(String yearSeparator) { builder = builder.withYearSeparator(yearSeparator); @@ -504,9 +544,11 @@ public LicenseHeaderConfig skipLinesMatching(String skipLinesMatching) { } /** - * @param updateYearWithLatest - * Will turn {@code 2004} into {@code 2004-2020}, and {@code 2004-2019} into {@code 2004-2020} - * Default value is false, unless {@link SpotlessExtensionImpl#ratchetFrom(String)} is used, in which case default value is true. + * @param updateYearWithLatest Will turn {@code 2004} into {@code 2004-2020}, + * and {@code 2004-2019} into {@code 2004-2020} + * Default value is false, unless + * {@link SpotlessExtensionImpl#ratchetFrom(String)} + * is used, in which case default value is true. */ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) { this.updateYearWithLatest = updateYearWithLatest; @@ -516,7 +558,8 @@ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) { FormatterStep createStep() { return builder.withYearModeLazy(() -> { - if ("true".equals(spotless.project.findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) { + if ("true".equals(spotless.project + .findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) { return YearMode.SET_FROM_GIT; } else { boolean updateYear = updateYearWithLatest == null ? getRatchetFrom() != null : updateYearWithLatest; @@ -527,22 +570,22 @@ FormatterStep createStep() { } /** - * @param licenseHeader - * Content that should be at the top of every file. - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param licenseHeader Content that should be at the top of every file. + * @param delimiter Spotless will look for a line that starts with this + * regular expression pattern to know what the "top" is. */ public LicenseHeaderConfig licenseHeader(String licenseHeader, String delimiter) { - LicenseHeaderConfig config = new LicenseHeaderConfig(LicenseHeaderStep.headerDelimiter(licenseHeader, delimiter)); + LicenseHeaderConfig config = new LicenseHeaderConfig( + LicenseHeaderStep.headerDelimiter(licenseHeader, delimiter)); addStep(config.createStep()); return config; } /** - * @param licenseHeaderFile - * Content that should be at the top of every file. - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param licenseHeaderFile Content that should be at the top of every file. + * @param delimiter Spotless will look for a line that starts with this + * regular expression pattern to know what the "top" + * is. */ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile, String delimiter) { LicenseHeaderConfig config = new LicenseHeaderConfig(LicenseHeaderStep.headerDelimiter(() -> { @@ -606,7 +649,8 @@ public T npmInstallCache(final Object npmInstallCache) { } public T npmInstallCache() { - this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); + this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), + SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); replaceStep(); return (T) this; } @@ -669,34 +713,93 @@ public PrettierConfig config(final Map prettierConfig) { @Override protected FormatterStep createStep() { final Project project = getProject(); - return PrettierFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return PrettierFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null, this.prettierConfig)); } } + /** + * 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 + * format{ ... }. + */ + public class BiomeGeneric 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 BiomeGeneric(String version) { + super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.BIOME, 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 Biome: + *
        + *
      • 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 BiomeGeneric language(String language) { + this.language = language; + replaceStep(); + return this; + } + + @Override + protected String getLanguage() { + return language; + } + + @Override + protected BiomeGeneric getThis() { + return this; + } + } + /** * 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. + * 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, version); + super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.ROME, version); } /** @@ -714,6 +817,7 @@ public RomeGeneric(String version) { * extension) *
    • json (JSON)
    • *
    + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -751,16 +855,40 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public RomeStepConfig biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public RomeStepConfig 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. */ + /** + * 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()); @@ -844,8 +972,9 @@ public void withinBlocks(String name, String open, String close, Action * spotless { @@ -858,33 +987,44 @@ public void withinBlocks(String name, String open, String close, Action */ - public void withinBlocks(String name, String open, String close, Class clazz, Action configure) { + public void withinBlocks(String name, String open, String close, Class clazz, + Action configure) { withinBlocksHelper(PipeStepPair.named(name).openClose(open, close), clazz, configure); } - /** Same as {@link #withinBlocks(String, String, String, Action)}, except instead of an open/close pair, you specify a regex with exactly one capturing group. */ + /** + * Same as {@link #withinBlocks(String, String, String, Action)}, except instead + * of an open/close pair, you specify a regex with exactly one capturing group. + */ public void withinBlocksRegex(String name, String regex, Action configure) { withinBlocksRegex(name, regex, FormatExtension.class, configure); } - /** Same as {@link #withinBlocksRegex(String, String, Action)}, except you can specify any language-specific subclass of {@link FormatExtension} to get language-specific steps. */ - public void withinBlocksRegex(String name, String regex, Class clazz, Action configure) { + /** + * Same as {@link #withinBlocksRegex(String, String, Action)}, except you can + * specify any language-specific subclass of {@link FormatExtension} to get + * language-specific steps. + */ + public void withinBlocksRegex(String name, String regex, Class clazz, + Action configure) { withinBlocksHelper(PipeStepPair.named(name).regex(regex), clazz, configure); } - private void withinBlocksHelper(PipeStepPair.Builder builder, Class clazz, Action configure) { + private void withinBlocksHelper(PipeStepPair.Builder builder, Class clazz, + Action configure) { // create the sub-extension T formatExtension = spotless.instantiateFormatExtension(clazz); // configure it configure.execute(formatExtension); // create a step which applies all of those steps as sub-steps - FormatterStep step = builder.buildStepWhichAppliesSubSteps(spotless.project.getRootDir().toPath(), formatExtension.steps); + FormatterStep step = builder.buildStepWhichAppliesSubSteps(spotless.project.getRootDir().toPath(), + formatExtension.steps); addStep(step); } /** - * Given a regex with *exactly one capturing group*, disables formatting - * inside that captured group. + * Given a regex with *exactly one capturing group*, disables formatting inside + * that captured group. */ public void toggleOffOnRegex(String regex) { this.togglePair = PipeStepPair.named(PipeStepPair.defaultToggleName()).regex(regex).buildPair(); @@ -900,7 +1040,10 @@ public void toggleOffOn() { toggleOffOn(PipeStepPair.defaultToggleOff(), PipeStepPair.defaultToggleOn()); } - /** Undoes all previous calls to {@link #toggleOffOn()} and {@link #toggleOffOn(String, String)}. */ + /** + * Undoes all previous calls to {@link #toggleOffOn()} and + * {@link #toggleOffOn(String, String)}. + */ public void toggleOffOnDisable() { this.togglePair = null; } @@ -923,11 +1066,13 @@ protected void setupTask(SpotlessTask task) { steps = this.steps; } if (targetExcludeContentPattern != null) { - steps.replaceAll(formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern)); + steps.replaceAll( + formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern)); } task.setSteps(steps); Directory projectDir = getProject().getLayout().getProjectDirectory(); - task.setLineEndingsPolicy(getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget))); + task.setLineEndingsPolicy( + getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget))); spotless.getRegisterDependenciesTask().hookSubprojectTask(task); task.setupRatchet(getRatchetFrom() != null ? getRatchetFrom() : ""); } @@ -943,31 +1088,38 @@ public SpotlessApply createIndependentApplyTask(String taskName) { } /** - * Creates an independent {@link SpotlessApply} for (very) unusual circumstances. + * Creates an independent {@link SpotlessApply} for (very) unusual + * circumstances. * - * Most users will not want this method. In the rare case that you want to create - * a {@code SpotlessApply} which is independent of the normal Spotless machinery, this will - * let you do that. + * Most users will not want this method. In the rare case that you want to + * create a {@code SpotlessApply} which is independent of the normal Spotless + * machinery, this will let you do that. * - * The returned task will not be hooked up to the global {@code spotlessApply}, and there will be no corresponding {@code check} task. + * The returned task will not be hooked up to the global {@code spotlessApply}, + * and there will be no corresponding {@code check} task. * * The task name must not end with `Apply`. * - * NOTE: does not respect the rarely-used {@code spotlessFiles} property. + * NOTE: does not respect the rarely-used {@code spotlessFiles} + * property. */ public TaskProvider createIndependentApplyTaskLazy(String taskName) { - Preconditions.checkArgument(!taskName.endsWith(SpotlessExtension.APPLY), "Task name must not end with " + SpotlessExtension.APPLY); - TaskProvider spotlessTask = spotless.project.getTasks().register(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class, task -> { - task.init(spotless.getRegisterDependenciesTask().getTaskService()); - setupTask(task); - // clean removes the SpotlessCache, so we have to run after clean - task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); - }); + Preconditions.checkArgument(!taskName.endsWith(SpotlessExtension.APPLY), + "Task name must not end with " + SpotlessExtension.APPLY); + TaskProvider spotlessTask = spotless.project.getTasks() + .register(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class, task -> { + task.init(spotless.getRegisterDependenciesTask().getTaskService()); + setupTask(task); + // clean removes the SpotlessCache, so we have to run after clean + task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); + }); // create the apply task - TaskProvider applyTask = spotless.project.getTasks().register(taskName, SpotlessApply.class, task -> { - task.dependsOn(spotlessTask); - task.init(spotlessTask.get()); - }); + TaskProvider applyTask = spotless.project.getTasks().register(taskName, SpotlessApply.class, + task -> { + task.dependsOn(spotlessTask); + task.init(spotlessTask.get()); + }); return applyTask; } 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 cd2682e971..c776004da3 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 @@ -34,6 +34,7 @@ import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; public class JavascriptExtension extends FormatExtension { @@ -58,7 +59,8 @@ public JavascriptEslintConfig eslint(Map devDependencies) { return eslint; } - public static abstract class EslintBaseConfig> extends NpmStepConfig> { + public static abstract class EslintBaseConfig> + extends NpmStepConfig> { Map devDependencies = new LinkedHashMap<>(); @Nullable @@ -67,7 +69,8 @@ public static abstract class EslintBaseConfig> ext @Nullable String configJs = null; - public EslintBaseConfig(Project project, Consumer replaceStep, Map devDependencies) { + public EslintBaseConfig(Project project, Consumer replaceStep, + Map devDependencies) { super(project, replaceStep); this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -103,13 +106,10 @@ public JavascriptEslintConfig(Map devDependencies) { public FormatterStep createStep() { final Project project = getProject(); - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return EslintFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } @@ -138,16 +138,40 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeJs biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeJs biome(String version) { + var biomeConfig = new BiomeJs(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()}. */ + @Deprecated public RomeJs rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * 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()); @@ -155,21 +179,49 @@ public RomeJs rome(String version) { } 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"); + private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, + "babel-flow", "flow"); + + /** + * Biome formatter step for JavaScript. + */ + public class BiomeJs extends RomeStepConfig { + /** + * Creates a new Biome formatter step config for formatting JavaScript files. + * Unless overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeJs(String version) { + super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "js?"; + } + + @Override + protected BiomeJs getThis() { + return this; + } + } /** * 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. + * 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, version); + super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override @@ -208,7 +260,9 @@ private void fixParserToJavascript() { } else { this.prettierConfig.put("parser", DEFAULT_PRETTIER_JS_PARSER); if (currentParser != null) { - getProject().getLogger().warn("Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_JS_PARSER); + getProject().getLogger().warn( + "Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", + DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_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 8648cacea9..cc16b7ed35 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 @@ -27,6 +27,7 @@ import com.diffplug.spotless.json.JsonPatchStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; +import com.diffplug.spotless.rome.EBiomeFlavor; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; @@ -59,16 +60,40 @@ public JacksonJsonGradleConfig jackson() { return new JacksonJsonGradleConfig(this); } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeJson biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeJson biome(String version) { + var biomeConfig = new BiomeJson(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()}. */ + @Deprecated public RomeJson rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * 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()); @@ -140,7 +165,9 @@ public GsonConfig version(String version) { } private FormatterStep createStep() { - return GsonStep.create(new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); + return GsonStep.create( + new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), + provisioner()); } } @@ -179,9 +206,37 @@ protected final FormatterStep createStep() { } } + /** + * Biome formatter step for JSON. + */ + public class BiomeJson extends RomeStepConfig { + /** + * Creates a new Biome formatter step config for formatting JSON files. Unless + * overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeJson(String version) { + super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "json"; + } + + @Override + protected BiomeJson getThis() { + return this; + } + } + /** * 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 @@ -190,7 +245,7 @@ public class RomeJson extends RomeStepConfig { * @param version Rome version to use. */ public RomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, version); + super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index f739e922d2..6b0ae893ac 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -28,12 +28,13 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; import com.diffplug.spotless.rome.RomeStep; public abstract class RomeStepConfig> { /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. */ @@ -41,16 +42,22 @@ public abstract class RomeStepConfig> { private Object configPath; /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. */ @Nullable private Object downloadDir; /** - * Optional path to the Rome executable. Either a version or a + * The flavor of Biome to use. Will be removed when we stop support the + * deprecated Rome project. + */ + private final EBiomeFlavor flavor; + + /** + * Optional path to the Biome executable. Either a version or a * pathToExe should be specified. When not given, an attempt is * made to download the executable for the given version from the network. When * given, the executable is used and the version parameter is @@ -59,10 +66,10 @@ public abstract class RomeStepConfig> { * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. */ @Nullable private Object pathToExe; @@ -73,12 +80,12 @@ public abstract class RomeStepConfig> { private final Project project; /** - * Replaces the current Rome formatter step with the given step. + * Replaces the current Biome formatter step with the given step. */ private final Consumer replaceStep; /** - * Rome version to download, applies only when no pathToExe is + * Biome version to download, applies only when no pathToExe is * specified explicitly. Either a version or a * pathToExe should be specified. When not given, a default known * version is used. For stable builds, it is recommended that you always set the @@ -88,15 +95,17 @@ public abstract class RomeStepConfig> { @Nullable private String version; - protected RomeStepConfig(Project project, Consumer replaceStep, String version) { + protected RomeStepConfig(Project project, Consumer replaceStep, EBiomeFlavor flavor, + String version) { this.project = requireNonNull(project); this.replaceStep = requireNonNull(replaceStep); + this.flavor = flavor; this.version = version; } /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. * @@ -109,10 +118,10 @@ public Self configPath(Object configPath) { } /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. * * @return This step for further configuration. */ @@ -123,16 +132,16 @@ public Self downloadDir(Object downloadDir) { } /** - * Optional path to the Rome executable. Overwrites the configured version. No - * attempt is made to download the Rome executable from the network. + * Optional path to the Biome executable. Overwrites the configured version. No + * attempt is made to download the Biome executable from the network. *

    * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. * * @return This step for further configuration. */ @@ -143,10 +152,10 @@ public Self pathToExe(Object pathToExe) { } /** - * Creates a new formatter step that formats code by calling the Rome + * Creates a new formatter step that formats code by calling the Biome * executable, using the current configuration. * - * @return A new formatter step for the Rome formatter. + * @return A new formatter step for the Biome formatter. */ protected FormatterStep createStep() { var builder = newBuilder(); @@ -161,7 +170,7 @@ protected FormatterStep createStep() { /** * 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: + * from the file name. Currently the following languages are supported by Biome: *

      *
    • js (JavaScript)
    • *
    • jsx (JavaScript + JSX)
    • @@ -179,12 +188,12 @@ protected FormatterStep createStep() { protected abstract String getLanguage(); /** - * @return This Rome config instance. + * @return This Biome config instance. */ protected abstract Self getThis(); /** - * Creates a new Rome step and replaces the existing Rome step in the list of + * Creates a new Biome step and replaces the existing Biome step in the list of * format steps. */ protected void replaceStep() { @@ -193,19 +202,18 @@ protected void replaceStep() { /** * Finds the data directory that can be used for storing shared data such as - * Rome executable globally. This is a directory in the local repository, e.g. + * Biome executable globally. This is a directory in the local repository, e.g. * ~/.m2/repository/com/diffplus/spotless/spotless-data. * * @return The directory for storing shared data. */ private File findDataDir() { - var currentRepo = project.getRepositories().stream() - .filter(r -> r instanceof MavenArtifactRepository) - .map(r -> (MavenArtifactRepository) r) - .filter(r -> "file".equals(r.getUrl().getScheme())) - .findAny().orElse(null); + var currentRepo = project.getRepositories().stream().filter(r -> r instanceof MavenArtifactRepository) + .map(r -> (MavenArtifactRepository) r).filter(r -> "file".equals(r.getUrl().getScheme())).findAny() + .orElse(null); // Temporarily add mavenLocal() repository to get its file URL - var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); + var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo + : project.getRepositories().mavenLocal(); try { // e.g. ~/.m2/repository/ var repoPath = Path.of(localRepo.getUrl()); @@ -220,29 +228,29 @@ private File findDataDir() { } /** - * A new builder for configuring a Rome step that either downloads the Rome + * A new builder for configuring a Biome step that either downloads the Biome * executable with the given version from the network, or uses the executable * from the given path. * - * @return A builder for a Rome step. + * @return A builder for a Biome step. */ private RomeStep newBuilder() { if (pathToExe != null) { var resolvedPathToExe = resolvePathToExe(); - return RomeStep.withExePath(resolvedPathToExe); + return RomeStep.withExePath(flavor, resolvedPathToExe); } else { var downloadDir = resolveDownloadDir(); - return RomeStep.withExeDownload(version, downloadDir); + return RomeStep.withExeDownload(flavor, version, downloadDir); } } /** - * Resolves the path to the Rome executable. When the path is only a file name, + * Resolves the path to the Biome executable. When the path is only a file name, * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. * - * @return The resolved path to the Rome executable. + * @return The resolved path to the Biome executable. */ private String resolvePathToExe() { var fileNameOnly = pathToExe instanceof String && Paths.get(pathToExe.toString()).getNameCount() == 1; @@ -254,18 +262,18 @@ private String resolvePathToExe() { } /** - * Resolves the directory to use for storing downloaded Rome executable. When a + * Resolves the directory to use for storing downloaded Biome executable. When a * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in + * current project's directory. Otherwise, use the {@code biome} sub folder in * the shared data directory. * - * @return The download directory for the Rome executable. + * @return The download directory for the Biome executable. */ private String resolveDownloadDir() { if (downloadDir != null) { return project.file(downloadDir).toString(); } else { - return findDataDir().toPath().resolve("rome").toString(); + return findDataDir().toPath().resolve(flavor.shortName()).toString(); } } } 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 929ea4423b..ad9bcc832b 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 @@ -38,6 +38,7 @@ import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; +import com.diffplug.spotless.rome.EBiomeFlavor; public class TypescriptExtension extends FormatExtension { @@ -58,7 +59,10 @@ public TypescriptFormatExtension tsfmt(String version) { return tsfmt(TsFmtFormatterStep.defaultDevDependenciesWithTsFmt(version)); } - /** Creates a {@code TypescriptFormatExtension} using exactly the specified npm packages. */ + /** + * Creates a {@code TypescriptFormatExtension} using exactly the specified npm + * packages. + */ public TypescriptFormatExtension tsfmt(Map devDependencies) { TypescriptFormatExtension tsfmt = new TypescriptFormatExtension(devDependencies); addStep(tsfmt.createStep()); @@ -114,15 +118,12 @@ private TypescriptFormatExtension configFile(TsConfigFileType filetype, Object p public FormatterStep createStep() { final Project project = getProject(); - return TsFmtFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), - typedConfigFile(), - config); + return TsFmtFormatterStep + .create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), + typedConfigFile(), config); } private TypedTsFmtConfigFile typedConfigFile() { @@ -154,7 +155,8 @@ public PrettierConfig prettier(Map devDependencies) { } /** - * Overrides the parser to be set to typescript, no matter what the user's config says. + * Overrides the parser to be set to typescript, no matter what the user's + * config says. */ public class TypescriptPrettierConfig extends PrettierConfig { TypescriptPrettierConfig(Map devDependencies) { @@ -173,7 +175,8 @@ private void fixParserToTypescript() { } else { final Object replaced = this.prettierConfig.put("parser", "typescript"); if (replaced != null) { - getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", replaced); + getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", + replaced); } } } @@ -211,52 +214,99 @@ public TypescriptEslintConfig tsconfigFile(Object path) { public FormatterStep createStep() { final Project project = getProject(); - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return EslintFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } protected EslintConfig eslintConfig() { - return new EslintTypescriptConfig( - configFilePath != null ? getProject().file(configFilePath) : null, - configJs, - typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + return new EslintTypescriptConfig(configFilePath != null ? getProject().file(configFilePath) : null, + configJs, typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); } } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeTs biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeTs biome(String version) { + var biomeConfig = new BiomeTs(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()}. */ + @Deprecated public RomeTs rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * 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 { + /** + * Creates a new Biome formatter step config for formatting TypeScript files. + * Unless overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeTs(String version) { + super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "ts?"; + } + + @Override + protected BiomeTs getThis() { + return this; + } + } + /** * 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. + * 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, version); + super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java new file mode 100644 index 0000000000..a2665a3bf1 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java @@ -0,0 +1,343 @@ +/* + * 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.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 BiomeIntegrationTest extends GradleIntegrationHarness { + /** + * Tests that biome 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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome 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'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome 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'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.json").toResource("biome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.json").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that biome 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'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.ts").toResource("biome/ts/fileBefore.ts"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.ts").sameAsResource("biome/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 'mybiome', {", + " target '**/*.nosj'", + " biome('1.2.0').language('json')", + " }", + "}"); + setFile("biome_test.nosj").toResource("biome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.nosj").sameAsResource("biome/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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('configs')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('configs')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-80.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/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/biome").getAbsoluteFile().toString(); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').downloadDir('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').downloadDir('target/bin/biome')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').pathToExe('biome/is/missing')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMybiomeApply'"); + 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 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').language('json')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("spotlessMybiome FAILED"); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Format with errors is disabled."); + assertThat(spotlessApply.getOutput()).contains("Step 'biome' found problem in 'biome_test.js'"); + } +} 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 index 4464b1cec7..0c12f9f500 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java @@ -288,7 +288,7 @@ void downloadDirRelative() throws Exception { } /** - * Tests that the build fails when given Rome executable does not exist. + * Tests that the build fails when given Biome executable does not exist. * * @throws Exception When a test failure occurs. */ @@ -311,7 +311,7 @@ void failureWhenExeNotFound() throws Exception { assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMyromeApply'"); - assertThat(spotlessApply.getOutput()).contains("Rome executable does not exist"); + assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist"); } /** 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 new file mode 100644 index 0000000000..23b6637519 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java @@ -0,0 +1,60 @@ +/* + * 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.EBiomeFlavor; + +/** + * 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 Biome() { + super(EBiomeFlavor.BIOME); + } + + /** + * 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 Biome: + *
        + *
          + *
        • 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/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index ed08718c65..ce7db9b926 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 @@ -41,6 +41,20 @@ public String licenseHeaderDelimiter() { return null; } + /** + * Adds a step to this format that format code with the Biome formatter. + * @param biome Biome configuration to use. + */ + 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 index 62d9d3fdec..628c051699 100644 --- 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 @@ -18,13 +18,17 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** - * 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 - * {@code }. + * See {@link Biome}. + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ public class Rome extends AbstractRome { + public Rome() { + super(EBiomeFlavor.ROME); + } + /** * Gets the language (syntax) of the input files to format. When * null or the empty string, the language is detected automatically 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 new file mode 100644 index 0000000000..07a341eee5 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java @@ -0,0 +1,33 @@ +/* + * 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.EBiomeFlavor; + +/** + * Biome formatter step for JavaScript. + */ +public class BiomeJs extends AbstractRome { + public BiomeJs() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "js?"; + } +} 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 b254110486..3f0a3f959c 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 @@ -42,6 +42,11 @@ public void addEslint(EslintJs eslint) { addStepFactory(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 index 60fb7077df..b5754f2b65 100644 --- 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 @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * 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(EBiomeFlavor.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 new file mode 100644 index 0000000000..13c2ab92f2 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java @@ -0,0 +1,33 @@ +/* + * 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.EBiomeFlavor; + +/** + * Biome formatter step for JSON. + */ +public class BiomeJson extends AbstractRome { + public BiomeJson() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "json"; + } +} 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 be5782b651..8baf379a5e 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 @@ -50,6 +50,11 @@ public void addJackson(JacksonJson jackson) { addStepFactory(jackson); } + public void addBiome(BiomeJson biome) { + addStepFactory(biome); + } + + @Deprecated public void addRome(RomeJson rome) { addStepFactory(rome); } 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 index 1cd044b759..7daab94afb 100644 --- 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 @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * 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(EBiomeFlavor.ROME); + } + @Override protected String getLanguage() { return "json"; 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/rome/AbstractRome.java index 33567b0a20..8b140ea381 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -22,19 +22,27 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.rome.EBiomeFlavor; import com.diffplug.spotless.rome.RomeStep; /** - * Factory for creating the Rome formatter step that can format format code in - * various types of language with Rome. Currently Rome support JavaScript, - * TypeScript, JSX, TSX, and JSON. See also - * https://github.com/rome/tools. - * It delegates to the Rome CLI executable. + * Factory for creating the Biome formatter step that can format format code in + * various types of language with Biome. Currently Biome supports JavaScript, + * TypeScript, JSX, TSX, and JSON. See also https://github.com/biomejs/biome. It + * delegates to the Biome CLI executable. */ public abstract class AbstractRome implements FormatterStepFactory { + /** Biome flavor to use. */ + private EBiomeFlavor flavor; + + protected AbstractRome(EBiomeFlavor flavor) { + this.flavor = flavor; + } + /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. */ @@ -42,12 +50,12 @@ public abstract class AbstractRome implements FormatterStepFactory { private String configPath; /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. *

      - * You can use an expression like ${user.home}/rome if you want to + * You can use an expression like ${user.home}/biome if you want to * use the home directory, or ${project.build.directory if you want * to use the target directory of the current project. */ @@ -55,7 +63,7 @@ public abstract class AbstractRome implements FormatterStepFactory { private String downloadDir; /** - * Optional path to the Rome executable. Either a version or a + * Optional path to the Biome executable. Either a version or a * pathToExe should be specified. When not given, an attempt is * made to download the executable for the given version from the network. When * given, the executable is used and the version parameter is @@ -64,16 +72,16 @@ public abstract class AbstractRome implements FormatterStepFactory { * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. */ @Parameter private String pathToExe; /** - * Rome version to download, applies only when no pathToExe is + * Biome version to download, applies only when no pathToExe is * specified explicitly. Either a version or a * pathToExe should be specified. When not given, a default known * version is used. For stable builds, it is recommended that you always set the @@ -99,7 +107,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { /** * 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: + * from the file name. Currently the following languages are supported by Biome: *

        *
      • js (JavaScript)
      • *
      • jsx (JavaScript + JSX)
      • @@ -117,26 +125,26 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { protected abstract String getLanguage(); /** - * A new builder for configuring a Rome step that either downloads the Rome + * A new builder for configuring a Biome step that either downloads the Biome * executable with the given version from the network, or uses the executable * from the given path. * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. - * @return A builder for a Rome step. + * @return A builder for a Biome step. */ private RomeStep newBuilder(FormatterStepConfig config) { if (pathToExe != null) { var resolvedExePath = resolveExePath(config); - return RomeStep.withExePath(resolvedExePath); + return RomeStep.withExePath(flavor, resolvedExePath); } else { var downloadDir = resolveDownloadDir(config); - return RomeStep.withExeDownload(version, downloadDir); + return RomeStep.withExeDownload(flavor, version, downloadDir); } } /** - * Resolves the path to the configuration file for Rome. Relative paths are + * Resolves the path to the configuration file for Biome. Relative paths are * resolved against the project's base directory. * * @param config Configuration from the Maven Mojo execution with details about @@ -148,14 +156,14 @@ private String resolveConfigFile(FormatterStepConfig config) { } /** - * Resolves the path to the Rome executable. When the path is only a file name, + * Resolves the path to the Biome executable. When the path is only a file name, * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. - * @return The resolved path to the Rome executable. + * @return The resolved path to the Biome executable. */ private String resolveExePath(FormatterStepConfig config) { var path = Paths.get(pathToExe); @@ -167,20 +175,20 @@ private String resolveExePath(FormatterStepConfig config) { } /** - * Resolves the directory to use for storing downloaded Rome executable. When a + * Resolves the directory to use for storing downloaded Biome executable. When a * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in - * the shared data directory. + * current project's directory. Otherwise, use the biome sub folder + * in the shared data directory. * * @param config Configuration for this step. - * @return The download directory for the Rome executable. + * @return The download directory for the Biome executable. */ private String resolveDownloadDir(FormatterStepConfig config) { final var fileLocator = config.getFileLocator(); if (downloadDir != null && !downloadDir.isBlank()) { return fileLocator.getBaseDir().toPath().resolve(downloadDir).toAbsolutePath().toString(); } else { - return fileLocator.getDataDir().toPath().resolve("rome").toString(); + return fileLocator.getDataDir().toPath().resolve(flavor.shortName()).toString(); } } } 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 new file mode 100644 index 0000000000..6fbcb31ee2 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java @@ -0,0 +1,33 @@ +/* + * 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.EBiomeFlavor; + +/** + * Biome formatter step for TypeScript. + */ +public class BiomeTs extends AbstractRome { + public BiomeTs() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "ts?"; + } +} 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 index ccee83744a..149d4208e3 100644 --- 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 @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * 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(EBiomeFlavor.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 ddae74db82..af25b8c773 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 @@ -46,6 +46,11 @@ public void addEslint(EslintTs eslint) { addStepFactory(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/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 398932dd19..5fd59752e6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -154,6 +154,11 @@ protected void writePomWithPrettierSteps(String includes, String... steps) throw writePom(formats(groupWithSteps("format", including(includes), steps))); } + protected void writePomWithBiomeSteps(String includes, String... steps) throws IOException { + writePom(formats(groupWithSteps("format", including(includes), steps))); + } + + @Deprecated protected void writePomWithRomeSteps(String includes, String... steps) throws IOException { writePom(formats(groupWithSteps("format", including(includes), steps))); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java new file mode 100644 index 0000000000..e015b934f5 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java @@ -0,0 +1,202 @@ +/* + * 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.biome; + +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; + +class BiomeMavenTest extends MavenIntegrationHarness { + /** + * Tests that Biome can be used as a generic formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asGenericStep() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that Biome can be used as a JavaScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJavaScriptStep() throws Exception { + writePomWithJavascriptSteps("**/*.js", "1.2.0"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome can be used as a JSON formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJsonStep() throws Exception { + writePomWithJsonSteps("**/*.json", "1.2.0"); + setFile("biome_test.json").toResource("biome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.json").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that biome can be used as a TypeScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asTypeScriptStep() throws Exception { + writePomWithTypescriptSteps("**/*.ts", "1.2.0"); + setFile("biome_test.ts").toResource("biome/ts/fileBefore.ts"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.ts").sameAsResource("biome/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 { + writePomWithBiomeSteps("**/*.nosj", "1.2.0json"); + setFile("biome_test.nosj").toResource("biome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.nosj").sameAsResource("biome/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(); + writePomWithBiomeSteps("**/*.js", + "1.2.0" + forXml(path) + ""); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.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 { + writePomWithBiomeSteps("**/*.js", "1.2.0configs"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.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 { + writePomWithBiomeSteps("**/*.js", "1.2.0configs"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-80.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/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/biome").getAbsoluteFile().toString(); + writePomWithBiomeSteps("**/*.js", + "1.2.0" + forXml(path) + ""); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").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 { + writePomWithBiomeSteps("**/*.js", + "1.2.0target/bin/biome"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").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 { + writePomWithBiomeSteps("**/*.js", "1.2.0biome/is/missing"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("biome_test.js").sameAsResource("biome/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 { + writePomWithBiomeSteps("**/*.js", "1.2.0json"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("biome_test.js").sameAsResource("biome/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 'biome' found problem in 'biome_test.js'"); + } +} 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 index 7ca3f7d981..f6a8107be1 100644 --- 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 @@ -24,6 +24,7 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; +@Deprecated class RomeMavenTest extends MavenIntegrationHarness { /** * Tests that rome can be used as a generic formatting step. @@ -181,7 +182,7 @@ void failureWhenExeNotFound() throws Exception { 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("Rome executable does not exist"); + assertThat(result.stdOutUtf8()).contains("Biome executable does not exist"); } /** diff --git a/testlib/src/main/resources/biome/config/line-width-120.json b/testlib/src/main/resources/biome/config/line-width-120.json new file mode 100644 index 0000000000..8f14afa3f8 --- /dev/null +++ b/testlib/src/main/resources/biome/config/line-width-120.json @@ -0,0 +1,11 @@ +{ + "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/biome/config/line-width-80.json b/testlib/src/main/resources/biome/config/line-width-80.json new file mode 100644 index 0000000000..5ec998bd97 --- /dev/null +++ b/testlib/src/main/resources/biome/config/line-width-80.json @@ -0,0 +1,11 @@ +{ + "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/biome/js/fileAfter.cjs b/testlib/src/main/resources/biome/js/fileAfter.cjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.cjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.js b/testlib/src/main/resources/biome/js/fileAfter.js new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.js @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.jsx b/testlib/src/main/resources/biome/js/fileAfter.jsx new file mode 100644 index 0000000000..313aceb6ed --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.jsx @@ -0,0 +1,3 @@ +export function Panel(cfg = {}) { + return
        {1 + 2}
        ; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.mjs b/testlib/src/main/resources/biome/js/fileAfter.mjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.mjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileBefore.cjs b/testlib/src/main/resources/biome/js/fileBefore.cjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.cjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.js b/testlib/src/main/resources/biome/js/fileBefore.js new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.js @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.jsx b/testlib/src/main/resources/biome/js/fileBefore.jsx new file mode 100644 index 0000000000..8e5d9834bc --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.jsx @@ -0,0 +1,4 @@ +export function Panel ( cfg={}){ + return (
        {1+2}
        + ) ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.mjs b/testlib/src/main/resources/biome/js/fileBefore.mjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.mjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/longLineAfter120.js b/testlib/src/main/resources/biome/js/longLineAfter120.js new file mode 100644 index 0000000000..68addc4b65 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineAfter120.js @@ -0,0 +1 @@ +const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; diff --git a/testlib/src/main/resources/biome/js/longLineAfter80.js b/testlib/src/main/resources/biome/js/longLineAfter80.js new file mode 100644 index 0000000000..dbdbd157e9 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineAfter80.js @@ -0,0 +1,13 @@ +const x = [ + "Hello", + "World", + "How", + "Are", + "You", + "Doing", + "Today", + "Such", + "A", + "Wondrous", + "Sunshine", +]; diff --git a/testlib/src/main/resources/biome/js/longLineBefore.js b/testlib/src/main/resources/biome/js/longLineBefore.js new file mode 100644 index 0000000000..fd59e429c2 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineBefore.js @@ -0,0 +1 @@ +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/biome/json/fileAfter.json b/testlib/src/main/resources/biome/json/fileAfter.json new file mode 100644 index 0000000000..468dac3297 --- /dev/null +++ b/testlib/src/main/resources/biome/json/fileAfter.json @@ -0,0 +1,5 @@ +{ + "a": [1, 2, 3], + "b": 9, + "c": null +} diff --git a/testlib/src/main/resources/biome/json/fileBefore.json b/testlib/src/main/resources/biome/json/fileBefore.json new file mode 100644 index 0000000000..77182284c7 --- /dev/null +++ b/testlib/src/main/resources/biome/json/fileBefore.json @@ -0,0 +1,7 @@ + { + "a":[1,2,3 + +], + "b":9, + "c" : null + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/ts/fileAfter.cts b/testlib/src/main/resources/biome/ts/fileAfter.cts new file mode 100644 index 0000000000..f854953234 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.cts @@ -0,0 +1,4 @@ +type Name = "World" | "Maven" | "Gradle"; +const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/biome/ts/fileAfter.mts b/testlib/src/main/resources/biome/ts/fileAfter.mts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.mts @@ -0,0 +1,4 @@ +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/biome/ts/fileAfter.ts b/testlib/src/main/resources/biome/ts/fileAfter.ts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.ts @@ -0,0 +1,4 @@ +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/biome/ts/fileAfter.tsx b/testlib/src/main/resources/biome/ts/fileAfter.tsx new file mode 100644 index 0000000000..15ef316142 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.tsx @@ -0,0 +1,7 @@ +export interface Cfg { + classname: string; + message: T; +} +const Panel = (cfg: Cfg): JSX.Element => { + return
        {String(cfg.message)}
        ; +}; diff --git a/testlib/src/main/resources/biome/ts/fileBefore.cts b/testlib/src/main/resources/biome/ts/fileBefore.cts new file mode 100644 index 0000000000..d4304287c0 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.cts @@ -0,0 +1,4 @@ +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/biome/ts/fileBefore.mts b/testlib/src/main/resources/biome/ts/fileBefore.mts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.mts @@ -0,0 +1,5 @@ +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/biome/ts/fileBefore.ts b/testlib/src/main/resources/biome/ts/fileBefore.ts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.ts @@ -0,0 +1,5 @@ +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/biome/ts/fileBefore.tsx b/testlib/src/main/resources/biome/ts/fileBefore.tsx new file mode 100644 index 0000000000..38f24f8440 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.tsx @@ -0,0 +1,8 @@ +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/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java index 5c4801d50a..f1761498c3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java @@ -38,247 +38,498 @@ static void createDownloadDir() throws IOException { downloadDir = userHome.resolve(".gradle").resolve("rome-dl-test").toAbsolutePath().normalize().toString(); } - /** - * Tests that files can be formatted without setting the input language - * explicitly. - */ @Nested - class AutoDetectLanguage { + @Deprecated + class Rome { /** - * Tests that a *.cjs file can be formatted without setting the input language + * Tests that files can be formatted without setting the input language * explicitly. */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); - } + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.ts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + /** + * Tests that a *.tsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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"); + @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(EBiomeFlavor.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(EBiomeFlavor.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(); + } } /** - * Test formatting with the line width in the config file set to 120. + * Tests that files can be formatted when setting the input language explicitly. */ - @Test - void testLineWidth80() { - var path = createRomeConfig("rome/config/line-width-80.json"); - var step = RomeStep.withExeDownload("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"); - } + @Nested + class ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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"); + } - 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 a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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"); + } } } - /** - * Tests that files can be formatted when setting the input language explicitly. - */ @Nested - class ExplicitLanguage { + class Biome { /** - * Tests that a *.cjs file can be formatted when setting the input language + * Tests that files can be formatted without setting the input language * explicitly. */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload("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"); - } + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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 when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload("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 *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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 when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload("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 *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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 *.json file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload("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 *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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 when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload("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 *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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("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 *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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 when setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload("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 *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); + } } - /** - * Tests that a *.ts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload("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"); + @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(EBiomeFlavor.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(EBiomeFlavor.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 a *.tsx file can be formatted when setting the input language - * explicitly. + * Tests that files can be formatted when setting the input language explicitly. */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload("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 ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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(EBiomeFlavor.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"); + } } } } From 967825f76ea6d3f3541c63b457ba758fca2eb654 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Fri, 15 Sep 2023 19:46:13 +0100 Subject: [PATCH 40/60] Update readme and changes for biome, #1804 --- CHANGES.md | 4 ++ README.md | 4 +- plugin-gradle/CHANGES.md | 4 ++ plugin-gradle/README.md | 133 +++++++++++++++++++-------------------- plugin-maven/CHANGES.md | 4 ++ plugin-maven/README.md | 124 ++++++++++++++++++------------------ 6 files changed, 143 insertions(+), 130 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 652e4ce38c..36ca61af71 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `biome` tag / function and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/README.md b/README.md index cd1e736014..0bfa395a23 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', -lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('biome.BiomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -153,7 +153,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | -| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`biome.BiomeStep`](lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 989b4ece12..d7907f0b87 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `biome(...)` function and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f81b897a4a..9c37f16902 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -64,9 +64,9 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Biome](#biome)) + - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [Biome](#biome), [jsonPatch](#jsonPatch)) - [YAML](#yaml) - [Gherkin](#gherkin) - Multiple languages @@ -76,7 +76,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - c, c++, c#, objective-c, protobuf, javascript, java - [eclipse web tools platform](#eclipse-web-tools-platform) - css, html, js, json, xml - - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) + - [Biome](#biome) ([binary detection](#biome-binary), [config file](#biome-configuration-file), [input language](#biome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -650,7 +650,7 @@ spotless { tsfmt() // has its own section below prettier() // has its own section below eslint() // has its own section below - rome() // has its own section below + biome() // has its own section below licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile // note the '(import|const|...' argument - this is a regex which identifies the top @@ -743,7 +743,7 @@ spotless { prettier() // has its own section below eslint() // has its own section below - rome() // has its own section below + biome() // has its own section below licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile } @@ -810,7 +810,7 @@ spotless { eclipseWtp('json') // see Eclipse web tools platform section gson() // has its own section below jackson() // has its own section below - rome() // has its own section below + biome() // has its own section below jsonPatch([]) // has its own section below } } @@ -1150,15 +1150,20 @@ Unlike Eclipse, Spotless WTP ignores per default external URIs in schema locatio external entities. To allow the access of external URIs, set the property `resolveExternalURI` to true. -## Rome +## Biome -[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, -does not require Node.js and as such, is pretty fast. It can currently format -JavaScript, TypeScript, JSX, and JSON, and may support -[more frontend languages](https://docs.rome.tools/internals/language_support/) -such as CSS in the future. +[homepage](https://biomejs.dev/). [changelog](https://github.com/biomejs/biome/blob/main/CHANGELOG.md). Biome is +a formatter that for the frontend written in Rust, which has a native binary, does not require Node.js and as such, +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. -You can use rome in any language-specific format for supported languages, but +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. ```gradle @@ -1167,72 +1172,73 @@ spotless { // you have to set the target manually target 'src/*/webapp/**/*.js' - // Download Rome from the network if not already downloaded, see below for more info - rome('12.0.0') + // Download Biome from the network if not already downloaded, see below for more info + biome('1.2.0') - // (optional) Path to the directory with the rome.json conig file - rome('12.0.0').configPath("path/config/dir") + // (optional) Path to the directory with the biome.json conig file + biome('1.2.0').configPath("path/config/dir") - // (optional) Rome will auto detect the language based on the file extension. + // (optional) Biome will auto detect the language based on the file extension. // See below for possible values. - rome('12.0.0').language("js") + biome('1.2.0').language("js") } } ``` **Limitations:** + - The auto-discovery of config files (up the file tree) will not work when using - Rome within spotless. + Biome within spotless. -To apply Rome to more kinds of files with a different configuration, just add +To apply Biome to more kinds of files with a different configuration, just add more formats: ```gradle spotless { - format 'rome-js', { + format 'biome-js', { target '**/*.js' - rome('12.0.0') + biome('1.2.0') } - format 'rome-ts', { + format 'biome-ts', { target '**/*.ts' - rome('12.0.0') + biome('1.2.0') } - format 'rome-json', { + format 'biome-json', { target '**/*.json' - rome('12.0.0') + biome('1.2.0') } } ``` -### Rome binary +### Biome binary -To format with Rome, spotless needs to find the Rome binary. By default, +To format with Biome, spotless needs to find the Biome binary. By default, spotless downloads the binary for the given version from the network. This should be fine in most cases, but may not work e.g. when there is not connection to the internet. -To download the Rome binary from the network, just specify a version: +To download the Biome binary from the network, just specify a version: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - rome('12.0.0') + biome('1.2.0') } } ``` -Spotless uses a default version when you do not specfiy a version, but this -may change at any time, so we recommend that you always set the Rome version +Spotless uses a default version when you do not specify a version, but this +may change at any time, so we recommend that you always set the Biome version you want to use. Optionally, you can also specify a directory for the downloaded -Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): +Biome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/biome`): ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' // Relative paths are resolved against the project's base directory - rome('12.0.0').downloadDir("${project.gradle.gradleUserHomeDir}/rome") + biome('1.2.0').downloadDir("${project.gradle.gradleUserHomeDir}/biome") } } ``` @@ -1241,68 +1247,59 @@ To use a fixed binary, omit the `version` and specify a `pathToExe`: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - rome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/rome") + biome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/biome") } } ``` Absolute paths are used as-is. Relative paths are resolved against the project's -base directory. To use a pre-installed Rome binary on the user's path, specify +base directory. To use a pre-installed Biome binary on the user's path, specify just a name without any slashes / backslashes: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - // Uses the "rome" command, which must be on the user's path. --> - rome().pathToExe('rome') + // Uses the "biome" command, which must be on the user's path. --> + biome().pathToExe('biome') } } ``` -### Rome configuration file +### Biome configuration file -Rome is a biased formatter and linter without many options, but there are a few -basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +Biome is a biased formatter and linter without many options, but there are a few +basic options. Biome uses a file named [biome.json](https://biomejs.dev/reference/configuration/) for its configuration. When none is specified, the default configuration from -Rome is used. To use a custom configuration: +Biome is used. To use a custom configuration: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - // Must point to the directory with the "rome.json" config file --> + // Must point to the directory with the "biome.json" config file --> // Relative paths are resolved against the project's base directory --> - rome('12.0.0').configPath('./config') + biome('1.2.0').configPath('./config') } } ``` -### Rome input language +### Biome input language -By default, Rome detects the language / syntax of the files to format +By default, Biome detects the language / syntax of the files to format automatically from the file extension. This may fail if your source code files have unusual extensions for some reason. If you are using the generic format, you can force a certain language like this: ```xml - - - - - src/**/typescript/**/*.mjson - - - - 12.0.0 - json - - - - - +spotless { + format 'biome', { + target 'src/**/typescript/**/*.mjson' + biome('1.2.0').language('json') + } +} ``` The following languages are currently recognized: diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b624299e71..22b77e4a7b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `` tag and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 8f91d8b08b..b6673b0221 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -49,15 +49,15 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Biome](#biome)) + - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [Biome](#biome), [jsonPatch](#jsonPatch)) - [YAML](#yaml) - [Gherkin](#gherkin) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install)) - [eclipse web tools platform](#eclipse-web-tools-platform) - - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) + - [Biome](#biome) ([binary detection](#biome-binary), [config file](#biome-configuration-file), [input language](#biome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -712,7 +712,7 @@ Currently, none of the available options can be configured yet. It uses only the - + /* (C)$YEAR */ @@ -823,7 +823,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr - + /* (C)$YEAR */ @@ -900,7 +900,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr - + @@ -1252,15 +1252,20 @@ to true. -## Rome +## Biome -[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, -does not require Node.js and as such, is pretty fast. It can currently format -JavaScript, TypeScript, JSX, and JSON, and may support -[more frontend languages](https://docs.rome.tools/internals/language_support/) -such as CSS in the future. +[homepage](https://biomejs.dev/). [changelog](https://github.com/biomejs/biome/blob/main/CHANGELOG.md). Biome is +a formatter that for the frontend written in Rust, which has a native binary, does not require Node.js and as such, +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. -You can use rome in any language-specific format for supported languages, but +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. ```xml @@ -1271,18 +1276,18 @@ usually you will be creating a generic format. src/**/typescript/**/*.ts - - - 12.0.0 + + + 1.2.0 - + ${project.basedir}/path/to/config/dir - + ts - + @@ -1290,85 +1295,85 @@ usually you will be creating a generic format. **Limitations:** - The auto-discovery of config files (up the file tree) will not work when using - Rome within spotless. + Biome within spotless. -To apply Rome to more kinds of files with a different configuration, just add -more formats +To apply Biome to more kinds of files with a different configuration, just add +more formats: ```xml - src/**/*.ts - src/**/*.js + src/**/*.ts + src/**/*.js ``` -### Rome binary +### Biome binary -To format with Rome, spotless needs to find the Rome binary. By default, +To format with Biome, spotless needs to find the Biome binary. By default, spotless downloads the binary for the given version from the network. This should be fine in most cases, but may not work e.g. when there is not connection to the internet. -To download the Rome binary from the network, just specify a version: +To download the Biome binary from the network, just specify a version: ```xml - - 12.0.0 - + + 1.2.0 + ``` -Spotless uses a default version when you do not specfiy a version, but this -may change at any time, so we recommend that you always set the Rome version +Spotless uses a default version when you do not specify a version, but this +may change at any time, so we recommend that you always set the Biome version you want to use. Optionally, you can also specify a directory for the downloaded -Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): +Biome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/biome`): ```xml - - 12.0.0 + + 1.2.0 - ${user.home}/rome - + ${user.home}/biome + ``` To use a fixed binary, omit the `version` and specify a `pathToExe`: ```xml - - ${project.basedir}/bin/rome - + + ${project.basedir}/bin/biome + ``` Absolute paths are used as-is. Relative paths are resolved against the project's -base directory. To use a pre-installed Rome binary on the user's path, specify +base directory. To use a pre-installed Biome binary on the user's path, specify just a name without any slashes / backslashes: ```xml - - - rome - + + + biome + ``` -### Rome configuration file +### Biome configuration file -Rome is a biased formatter and linter without many options, but there are a few -basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +Biome is a biased formatter and linter without many options, but there are a few +basic options. Biome uses a file named [biome.json](https://biomejs.dev/reference/configuration/) for its configuration. When none is specified, the default configuration from -Rome is used. To use a custom configuration: +Biome is used. To use a custom configuration: ```xml - - + + ${project.basedir} - + ``` -### Rome input language +### Biome input language -By default, Rome detects the language / syntax of the files to format +By default, Biome detects the language / syntax of the files to format automatically from the file extension. This may fail if your source code files have unusual extensions for some reason. If you are using the generic format, you can force a certain language like this: @@ -1381,12 +1386,11 @@ you can force a certain language like this: src/**/typescript/**/*.mjson - - 12.0.0 + + 1.2.0 json - - - + + ``` From 4a9e443bae171637e915a1b5bf11d90a21e74fa1 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Fri, 15 Sep 2023 20:37:56 +0100 Subject: [PATCH 41/60] Apply spotless --- .../diffplug/spotless/rome/EBiomeFlavor.java | 19 +++++++++++++++++-- .../gradle/spotless/FormatExtension.java | 14 +++++++------- .../gradle/spotless/JavascriptExtension.java | 6 +++--- .../gradle/spotless/JsonExtension.java | 6 +++--- .../gradle/spotless/TypescriptExtension.java | 6 +++--- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java index e47662f154..efe9a74807 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java @@ -1,3 +1,18 @@ +/* + * 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.rome; /** @@ -13,7 +28,7 @@ public enum EBiomeFlavor { /** * The old deprecated Rome project. - * + * * @deprecated Will be removed once the old Rome project is not supported * anymore. */ @@ -77,4 +92,4 @@ public String getUrlPattern() { public String shortName() { return shortName; } -} \ No newline at end of file +} 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 61fb0a6e5b..6c62469b04 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 @@ -735,7 +735,7 @@ public class BiomeGeneric extends RomeStepConfig { /** * 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. */ @@ -758,7 +758,7 @@ public BiomeGeneric(String version) { * extension) *
      • json (JSON)
      • *
      - * + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -783,7 +783,7 @@ 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 @@ -794,7 +794,7 @@ public class RomeGeneric extends RomeStepConfig { /** * 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. */ @@ -817,7 +817,7 @@ public RomeGeneric(String version) { * extension) *
    • json (JSON)
    • *
    - * + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -875,7 +875,7 @@ public RomeStepConfig biome(String version) { * 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 @@ -885,7 +885,7 @@ public RomeStepConfig rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated 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 c776004da3..4dc810ce6b 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 @@ -158,7 +158,7 @@ public BiomeJs biome(String version) { * 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 @@ -168,7 +168,7 @@ public RomeJs rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -209,7 +209,7 @@ protected BiomeJs getThis() { /** * Rome formatter step for JavaScript. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated 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 cc16b7ed35..8273d81e79 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 @@ -80,7 +80,7 @@ public BiomeJson biome(String version) { * 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 @@ -90,7 +90,7 @@ public RomeJson rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -233,7 +233,7 @@ protected BiomeJson getThis() { /** * Rome formatter step for JSON. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated 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 ad9bcc832b..f21bd9ed39 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 @@ -247,7 +247,7 @@ public BiomeTs biome(String version) { * 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 @@ -257,7 +257,7 @@ public RomeTs rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -294,7 +294,7 @@ protected BiomeTs getThis() { /** * Rome formatter step for TypeScript. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated From ddaf8d47b044adb87580bdeb096ac15771d4fcf8 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 16 Sep 2023 09:31:41 +0100 Subject: [PATCH 42/60] Enum naming convention, EBiomeFlavor -> BiomeFlavor --- .../rome/{EBiomeFlavor.java => BiomeFlavor.java} | 4 ++-- .../spotless/rome/RomeExecutableDownloader.java | 4 ++-- .../java/com/diffplug/spotless/rome/RomeStep.java | 12 ++++++------ .../diffplug/gradle/spotless/FormatExtension.java | 6 +++--- .../gradle/spotless/JavascriptExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/JsonExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/RomeStepConfig.java | 6 +++--- .../gradle/spotless/TypescriptExtension.java | 6 +++--- .../com/diffplug/spotless/maven/generic/Biome.java | 4 ++-- .../com/diffplug/spotless/maven/generic/Rome.java | 4 ++-- .../diffplug/spotless/maven/javascript/BiomeJs.java | 4 ++-- .../diffplug/spotless/maven/javascript/RomeJs.java | 4 ++-- .../com/diffplug/spotless/maven/json/BiomeJson.java | 4 ++-- .../com/diffplug/spotless/maven/json/RomeJson.java | 4 ++-- .../diffplug/spotless/maven/rome/AbstractRome.java | 6 +++--- .../diffplug/spotless/maven/typescript/BiomeTs.java | 4 ++-- .../diffplug/spotless/maven/typescript/RomeTs.java | 4 ++-- 17 files changed, 44 insertions(+), 44 deletions(-) rename lib/src/main/java/com/diffplug/spotless/rome/{EBiomeFlavor.java => BiomeFlavor.java} (95%) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java similarity index 95% rename from lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java rename to lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java index efe9a74807..dbfd43eee9 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java @@ -21,7 +21,7 @@ *

    * Will be removed once the old Rome project is not supported anymore. */ -public enum EBiomeFlavor { +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"), @@ -42,7 +42,7 @@ public enum EBiomeFlavor { private final String shortName; private final String urlPattern; - EBiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, + BiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, String urlPattern) { this.shortName = shortName; this.defaultVersion = defaultVersion; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 7ff0bdb622..052f72def4 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -71,7 +71,7 @@ final class RomeExecutableDownloader { private final Path downloadDir; - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Creates a new downloader for the Biome executable. The executable files are @@ -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(EBiomeFlavor flavor, Path downloadDir) { + public RomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) { this.flavor = flavor; this.downloadDir = downloadDir; } diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index 88c35c8662..5ba33d593d 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -74,7 +74,7 @@ public class RomeStep { * Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project. */ @Deprecated - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Path to the Biome executable. Can be null, but either a path to @@ -113,7 +113,7 @@ 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(EBiomeFlavor flavor, String version, String downloadDir) { + public static RomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) { return new RomeStep(flavor, version, null, downloadDir); } @@ -125,7 +125,7 @@ public static RomeStep withExeDownload(EBiomeFlavor flavor, String version, Stri * @param pathToExe Path to the Biome executable to use. * @return A new Biome step that format with the given executable. */ - public static RomeStep withExePath(EBiomeFlavor flavor, String pathToExe) { + public static RomeStep withExePath(BiomeFlavor flavor, String pathToExe) { return new RomeStep(flavor, null, pathToExe, null); } @@ -154,7 +154,7 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p * * @return The default version for Biome. */ - private static String defaultVersion(EBiomeFlavor flavor) { + private static String defaultVersion(BiomeFlavor flavor) { return flavor.defaultVersion(); } @@ -198,7 +198,7 @@ private static String resolveNameAgainstPath(String name) throws IOException, In * Checks the Biome config path. When the config path does not exist or when it * does not contain a file named {@code biome.json}, an error is thrown. */ - private static void validateBiomeConfigPath(EBiomeFlavor flavor, String configPath) { + private static void validateBiomeConfigPath(BiomeFlavor flavor, String configPath) { if (configPath == null) { return; } @@ -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(EBiomeFlavor flavor, String version, String pathToExe, String downloadDir) { + private RomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) { this.flavor = flavor; this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor); this.pathToExe = pathToExe; 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 6c62469b04..30fded9d5f 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 @@ -67,7 +67,7 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import groovy.lang.Closure; @@ -740,7 +740,7 @@ public class BiomeGeneric extends RomeStepConfig { * null. */ public BiomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), FormatExtension.this::replaceStep, BiomeFlavor.BIOME, version); } /** @@ -799,7 +799,7 @@ public class RomeGeneric extends RomeStepConfig { * null. */ public RomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), FormatExtension.this::replaceStep, BiomeFlavor.ROME, version); } /** 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 4dc810ce6b..b14bd29ab8 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 @@ -34,7 +34,7 @@ import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class JavascriptExtension extends FormatExtension { @@ -193,7 +193,7 @@ public class BiomeJs extends RomeStepConfig { * @param version Biome version to use. */ public BiomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), JavascriptExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -221,7 +221,7 @@ public class RomeJs extends RomeStepConfig { * @param version Rome version to use. */ public RomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), JavascriptExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override 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 8273d81e79..441e25b93d 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 @@ -27,7 +27,7 @@ import com.diffplug.spotless.json.JsonPatchStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; @@ -217,7 +217,7 @@ public class BiomeJson extends RomeStepConfig { * @param version Biome version to use. */ public BiomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), JsonExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -245,7 +245,7 @@ public class RomeJson extends RomeStepConfig { * @param version Rome version to use. */ public RomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), JsonExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index 6b0ae893ac..98c4000a8b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -28,7 +28,7 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import com.diffplug.spotless.rome.RomeStep; public abstract class RomeStepConfig> { @@ -54,7 +54,7 @@ public abstract class RomeStepConfig> { * The flavor of Biome to use. Will be removed when we stop support the * deprecated Rome project. */ - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Optional path to the Biome executable. Either a version or a @@ -95,7 +95,7 @@ public abstract class RomeStepConfig> { @Nullable private String version; - protected RomeStepConfig(Project project, Consumer replaceStep, EBiomeFlavor flavor, + protected RomeStepConfig(Project project, Consumer replaceStep, BiomeFlavor flavor, String version) { this.project = requireNonNull(project); this.replaceStep = requireNonNull(replaceStep); 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 f21bd9ed39..190a2f8e20 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 @@ -38,7 +38,7 @@ import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class TypescriptExtension extends FormatExtension { @@ -278,7 +278,7 @@ public class BiomeTs extends RomeStepConfig { * @param version Biome version to use. */ public BiomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), TypescriptExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -306,7 +306,7 @@ public class RomeTs extends RomeStepConfig { * @param version Rome version to use. */ public RomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), TypescriptExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override 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 23b6637519..e096a14734 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 @@ -18,7 +18,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Generic Biome formatter step that detects the language of the input file from @@ -27,7 +27,7 @@ */ public class Biome extends AbstractRome { public Biome() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } /** 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 index 628c051699..53080fe546 100644 --- 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 @@ -18,7 +18,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * See {@link Biome}. @@ -26,7 +26,7 @@ */ public class Rome extends AbstractRome { public Rome() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } /** 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 07a341eee5..4d52f4cc80 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 @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for JavaScript. */ public class BiomeJs extends AbstractRome { public BiomeJs() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override 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 index b5754f2b65..405809c7a7 100644 --- 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 @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for JavaScript. @@ -25,7 +25,7 @@ @Deprecated public class RomeJs extends AbstractRome { public RomeJs() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override 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 13c2ab92f2..a8d329d725 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 @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for JSON. */ public class BiomeJson extends AbstractRome { public BiomeJson() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override 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 index 7daab94afb..2959d5a055 100644 --- 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 @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for JSON. @@ -25,7 +25,7 @@ @Deprecated public class RomeJson extends AbstractRome { public RomeJson() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override 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/rome/AbstractRome.java index 8b140ea381..da66bf37a0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -22,7 +22,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import com.diffplug.spotless.rome.RomeStep; /** @@ -34,9 +34,9 @@ */ public abstract class AbstractRome implements FormatterStepFactory { /** Biome flavor to use. */ - private EBiomeFlavor flavor; + private BiomeFlavor flavor; - protected AbstractRome(EBiomeFlavor flavor) { + protected AbstractRome(BiomeFlavor flavor) { this.flavor = flavor; } 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 6fbcb31ee2..a99e633a42 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 @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for TypeScript. */ public class BiomeTs extends AbstractRome { public BiomeTs() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override 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 index 149d4208e3..f6ea80581d 100644 --- 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 @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for TypeScript. @@ -25,7 +25,7 @@ @Deprecated public class RomeTs extends AbstractRome { public RomeTs() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override From a1b2e82f5cb23d8d52ef51450358c8fea198ceb8 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 16 Sep 2023 10:38:44 +0100 Subject: [PATCH 43/60] Fix test compilation --- .../diffplug/spotless/rome/RomeStepTest.java | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java index f1761498c3..f723a561c2 100644 --- a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java @@ -53,7 +53,7 @@ class AutoDetectLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -64,7 +64,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -75,7 +75,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -86,7 +86,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -97,7 +97,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -108,7 +108,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -119,7 +119,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -130,7 +130,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -141,7 +141,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + 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"); } @@ -155,7 +155,7 @@ class ConfigFile { @Test void testLineWidth120() { var path = createRomeConfig("rome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + 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"); } @@ -166,7 +166,7 @@ void testLineWidth120() { @Test void testLineWidth80() { var path = createRomeConfig("rome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + 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"); } @@ -191,7 +191,7 @@ class ExplicitLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -202,7 +202,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -213,7 +213,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -224,7 +224,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("json").create(); + 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"); } @@ -235,7 +235,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("jsx").create(); + 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"); } @@ -246,7 +246,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -257,7 +257,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -268,7 +268,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -279,7 +279,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("tsx").create(); + 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"); } @@ -300,7 +300,7 @@ class AutoDetectLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -311,7 +311,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -322,7 +322,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -333,7 +333,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -344,7 +344,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -355,7 +355,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -366,7 +366,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -377,7 +377,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -388,7 +388,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + 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"); } @@ -402,7 +402,7 @@ class ConfigFile { @Test void testLineWidth120() { var path = createBiomeConfig("biome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + 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"); } @@ -413,7 +413,7 @@ void testLineWidth120() { @Test void testLineWidth80() { var path = createBiomeConfig("biome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + 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"); } @@ -438,7 +438,7 @@ class ExplicitLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -449,7 +449,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -460,7 +460,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -471,7 +471,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); + 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"); } @@ -482,7 +482,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); + 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"); } @@ -493,7 +493,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + 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"); } @@ -504,7 +504,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -515,7 +515,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + 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"); } @@ -526,7 +526,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); + 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"); } From 7de7991d86f867ed7c528d915eec493c2699be25 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 08:41:39 +0800 Subject: [PATCH 44/60] Compat old ktlint users --- CHANGES.md | 2 +- .../glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 5 +++++ .../glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java | 1 - plugin-gradle/CHANGES.md | 3 +-- plugin-gradle/README.md | 1 - .../com/diffplug/gradle/spotless/KotlinExtensionTest.java | 1 - .../diffplug/gradle/spotless/KotlinGradleExtensionTest.java | 1 - plugin-maven/CHANGES.md | 3 +-- plugin-maven/README.md | 1 - .../java/com/diffplug/spotless/maven/kotlin/KtlintTest.java | 1 - 10 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2d379a874..4a831e9d0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.41.0] - 2023-08-29 ### Added diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 7b12169400..9c2792f769 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -132,6 +132,11 @@ private static EditorConfigOverride createEditorConfigOverride(final List .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + // The default style had been changed from intellij_idea to ktlint_official in version 1.0.0 + if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) { + editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); + } + // Create config properties based on provided property names and values @SuppressWarnings("unchecked") Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 5ed2517c6f..1f8e6023b4 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -54,7 +54,6 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b66fcbc262..feb5c67844 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). - The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9a4b84c4dd..03a94e5004 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -405,7 +405,6 @@ spotless { .editorConfigOverride( mapOf( "indent_size" to 2, - "ktlint_code_style" to "intellij_idea", ) ) } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index a2fa7c16e7..1c23728244 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -73,7 +73,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlin {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 6d7bdf351a..7dade5f2ff 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -52,7 +52,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlinGradle {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 54f92898a1..ef310b3ea2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). -The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.39.0] - 2023-08-29 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9419490d3e..f63d7faed9 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -413,7 +413,6 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. true true - intellij_idea ``` diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index f3f360dc5d..060e0de84f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -36,7 +36,6 @@ void testKtlintEditorConfigOverride() throws Exception { " \n" + " true\n" + " true\n" + - " intellij_idea\n" + " \n" + ""); From 80a83a8be5d5f585809da9cb5665e1dd529a0c64 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:09:16 +0000 Subject: [PATCH 45/60] chore(deps): update plugin dev.equo.ide to v1.7.3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 11ac98ec93..1a9f631f20 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,7 +25,7 @@ plugins { // https://plugins.gradle.org/plugin/com.gradle.enterprise id 'com.gradle.enterprise' version '3.14.1' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '1.0.1' apply false + id 'dev.equo.ide' version '1.7.3' apply false } dependencyResolutionManagement { From 4047ae01329491b1f3d79f4f792f842d9b526ea8 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 22:41:20 +0800 Subject: [PATCH 46/60] Add Category.LIBRARY attr to resolve ktlint deps --- .../com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 12 +++--------- .../java/com/diffplug/spotless/TestProvisioner.java | 12 +++--------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index bedbb4a071..d08c59b839 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -39,7 +39,7 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index a92d583596..288cc10c72 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -27,6 +27,7 @@ import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.api.initialization.dsl.ScriptHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,6 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.kotlin.KtLintStep; /** Should be package-private. */ class GradleProvisioner { @@ -122,14 +122,8 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setCanBeConsumed(false); config.setVisible(false); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); return config.resolve(); } catch (Exception e) { diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 6a942d8ca3..e06640ccfd 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -32,6 +32,7 @@ import org.gradle.api.artifacts.ResolveException; import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.testfixtures.ProjectBuilder; import com.diffplug.common.base.Errors; @@ -39,7 +40,6 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; -import com.diffplug.spotless.kotlin.KtLintStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -71,14 +71,8 @@ private static Provisioner createWithRepositories(Consumer re config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); try { return config.resolve(); From 196afc0f1be5f1171bed1eb8617554f59200db95 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 26 Sep 2023 12:36:59 +0800 Subject: [PATCH 47/60] Enable type-safe project accessors https://docs.gradle.org/7.6/userguide/declaring_dependencies.html#sec:type-safe-project-accessors --- _ext/gradle/java-setup.gradle | 2 +- lib-extra/build.gradle | 4 ++-- plugin-gradle/build.gradle | 6 +++--- plugin-maven/build.gradle | 4 ++-- settings.gradle | 1 + testlib/build.gradle | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 0d620a6519..d1a1075d84 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -19,7 +19,7 @@ tasks.withType(JavaCompile).configureEach { dependencies { testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" - testImplementation project(':testlib') + testImplementation projects.testlib } tasks.withType(Test).configureEach { diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 1158ca0893..35381f08a4 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') String VER_SOLSTICE = '1.3.1' dependencies { - api project(':lib') + api projects.lib // misc useful utilities implementation "com.diffplug.durian:durian-core:${VER_DURIAN}" implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" @@ -20,7 +20,7 @@ dependencies { implementation "dev.equo.ide:solstice:${VER_SOLSTICE}" // testing - testImplementation project(':testlib') + testImplementation projects.testlib testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 021155abfe..ba800173a2 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -10,8 +10,8 @@ apply from: rootProject.file('gradle/spotless-freshmark.gradle') dependencies { if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { - api project(':lib') - api project(':lib-extra') + api projects.lib + api projects.libExtra } else { api "com.diffplug.spotless:spotless-lib:${rootProject.spotlessChangelog.versionLast}" api "com.diffplug.spotless:spotless-lib-extra:${rootProject.spotlessChangelog.versionLast}" @@ -21,7 +21,7 @@ dependencies { implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" - testImplementation project(':testlib') + testImplementation projects.testlib testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 7cfb38c2e9..3f46e6eba7 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -30,8 +30,8 @@ String VER_MAVEN_API = '3.0' String VER_ECLIPSE_AETHER = '1.1.0' String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { - implementation project(':lib') - implementation project(':lib-extra') + implementation projects.lib + implementation projects.libExtra compileOnly "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_API}" diff --git a/settings.gradle b/settings.gradle index 11ac98ec93..3ef45ca2f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -71,6 +71,7 @@ gradleEnterprise { } enableFeaturePreview("STABLE_CONFIGURATION_CACHE") +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") rootProject.name = 'spotless' diff --git a/testlib/build.gradle b/testlib/build.gradle index afa6a67a91..12b3bcd135 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -6,8 +6,8 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') dependencies { - api project(':lib') - api files(project(':lib').sourceSets.sortPom.output.classesDirs) + api projects.lib + api files(projects.lib.dependencyProject.sourceSets.sortPom.output.classesDirs) api "com.diffplug.durian:durian-core:${VER_DURIAN}" api "com.diffplug.durian:durian-testlib:${VER_DURIAN}" api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" From 68c78405aba32f3d7f1bff6e121e6877ce8d1f13 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Sep 2023 23:55:48 -0700 Subject: [PATCH 48/60] Fixup changelog. --- plugin-gradle/README.md | 2 +- plugin-maven/CHANGES.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index e0d6371236..d58d698303 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -592,7 +592,7 @@ To apply flexmark to all of the `.md` files in your project, use this snippet: spotless { flexmark { target '**/*.md' // you have to set the target manually - flexmarkFormatter() // or flexmarkFormatter('0.64.6') // version is optional + flexmark() // or flexmark('0.64.6') // version is optional } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9d413397e2..bc31c30e4b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,9 +5,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). - ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) +### Changes +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) ## [2.39.0] - 2023-08-29 ### Added From beed923037ffebd2a857a2e6dde1e6ee1837b99e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Sep 2023 23:56:29 -0700 Subject: [PATCH 49/60] `flexmarkFormatter` -> `flexmark` --- .../com/diffplug/gradle/spotless/FlexmarkExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/FlexmarkExtensionTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java index 047b0eda73..d1f941613b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java @@ -30,11 +30,11 @@ public FlexmarkExtension(SpotlessExtension spotless) { super(spotless); } - public FlexmarkFormatterConfig flexmarkFormatter() { - return flexmarkFormatter(FlexmarkStep.defaultVersion()); + public FlexmarkFormatterConfig flexmark() { + return flexmark(FlexmarkStep.defaultVersion()); } - public FlexmarkFormatterConfig flexmarkFormatter(String version) { + public FlexmarkFormatterConfig flexmark(String version) { return new FlexmarkFormatterConfig(version); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java index 873baba744..6264c0c230 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " flexmark {", " target '*.md'", - " flexmarkFormatter()", + " flexmark()", " }", "}"); setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md"); From 9ac3edca3fe802321fa68924a52ed3c595ecbd48 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 00:06:45 -0700 Subject: [PATCH 50/60] Bump 64.6 -> 64.8. --- CHANGES.md | 2 +- .../main/java/com/diffplug/spotless/markdown/FlexmarkStep.java | 2 +- plugin-gradle/README.md | 2 +- plugin-maven/CHANGES.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4ae2a3aafe..71cde3f643 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,7 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) ## [2.41.0] - 2023-08-29 diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java index b4159830e7..65d903cba3 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java @@ -29,7 +29,7 @@ public class FlexmarkStep { // prevent direct instantiation private FlexmarkStep() {} - private static final String DEFAULT_VERSION = "0.64.6"; + private static final String DEFAULT_VERSION = "0.64.8"; private static final String NAME = "flexmark-java"; private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:"; diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c7303bbc9e..8aef3ac234 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -592,7 +592,7 @@ To apply flexmark to all of the `.md` files in your project, use this snippet: spotless { flexmark { target '**/*.md' // you have to set the target manually - flexmark() // or flexmark('0.64.6') // version is optional + flexmark() // or flexmark('0.64.8') // version is optional } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e04a360e26..72d1e502a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,7 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) ## [2.39.0] - 2023-08-29 From 7faf344c98ac99b515a75515028a9060fba5f1dd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 07:10:44 +0000 Subject: [PATCH 51/60] chore(deps): update plugin com.gradle.enterprise to v3.15 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 3ef45ca2f0..6387e3b2c2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.14.1' + id 'com.gradle.enterprise' version '3.15' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From a35af334cec87aa26c7f4b9b8cfa91b0e5dd9fa1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:44:26 +0200 Subject: [PATCH 52/60] Support configuration of P2 mirrors in maven plugin (fixes #1697) --- .../spotless/extra/EquoBasedStepBuilder.java | 7 +++++ .../com/diffplug/spotless/extra/P2Mirror.java | 30 +++++++++++++++++++ .../spotless/maven/cpp/EclipseCdt.java | 7 +++++ .../spotless/maven/groovy/GrEclipse.java | 7 +++++ .../diffplug/spotless/maven/java/Eclipse.java | 7 +++++ 5 files changed, 58 insertions(+) create mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 586deeb5bf..22ba268426 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -15,10 +15,13 @@ */ package com.diffplug.spotless.extra; +import static java.util.stream.Collectors.toMap; + import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -76,6 +79,10 @@ public void setP2Mirrors(Map p2Mirrors) { this.p2Mirrors = Map.copyOf(p2Mirrors); } + public void setP2Mirrors(Collection p2Mirrors) { + this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl)); + } + /** Returns the FormatterStep (whose state will be calculated lazily). */ public FormatterStep build() { return FormatterStep.createLazy(formatterName, this::get, stateToFormatter); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java new file mode 100644 index 0000000000..f6ce6727b2 --- /dev/null +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -0,0 +1,30 @@ +/* + * 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.extra; + +public class P2Mirror { + + private String prefix; + private String url; + + public String getPrefix() { + return prefix; + } + + public String getUrl() { + return url; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java index a92e7b2423..92f4229ed3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.cpp; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class EclipseCdt implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java index 8836993cce..67ab40fbf2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.groovy; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class GrEclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); grEclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + grEclipseConfig.setP2Mirrors(p2Mirrors); return grEclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java index e30a4faad9..8d5869cc8e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.java; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class Eclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseJdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } From d0fca7a14d8513883c53f2f1a845fb6becc29267 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:54:23 +0200 Subject: [PATCH 53/60] Update changelog --- CHANGES.md | 1 + plugin-maven/CHANGES.md | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 71cde3f643..24dfc66c39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `biome` tag / function and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 72d1e502a1..5a75a717a0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `` tag and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories ([#1697](https://github.com/diffplug/spotless/issues/1697)): + ``` + + + + https://download.eclipse.org/ + https://some.internal.mirror/eclipse + + + + ``` + Mirrors are selected by prefix match, for example `https://download.eclipse.org/eclipse/updates/4.26/` will be redirected to `https://some.internal.mirror/eclipse/eclipse/updates/4.26/`. + The same configuration exists for `` and ``. ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes From 34d92f2c892c942463d70fbdb30ca5651be8ff3d Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 28 Sep 2023 17:11:23 +0800 Subject: [PATCH 54/60] Ignore Ktlint updates by Renovate https://docs.renovatebot.com/configuration-options/#ignoredeps --- renovate.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/renovate.json b/renovate.json index 7bd954555f..2b278dfe17 100644 --- a/renovate.json +++ b/renovate.json @@ -2,5 +2,14 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" + ], + "packageRules": [ + { + "groupName": "Ktlint", + "enabled": false, + "matchPackagePatterns": [ + "com.pinterest.ktlint:*" + ] + } ] } From 56cea6d8bb12bd90a749e00cb7d4670a67604d1b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:52:12 +0000 Subject: [PATCH 55/60] fix(deps): update dependency org.eclipse.jgit:org.eclipse.jgit to v6.7.0.202309050840-r --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce29bbfaeb..8312afaed3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,7 +29,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=6.6.0.202305301015-r +VER_JGIT=6.7.0.202309050840-r VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From c86699083424701a3582d35c8f4e9adf0b889980 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:13:06 +0000 Subject: [PATCH 56/60] fix(deps): update dependency org.mockito:mockito-core to v5.5.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce29bbfaeb..af3c2fd9c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.6.0.202305301015-r VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.3.1 +VER_MOCKITO=5.5.0 From 479248d566a0fd8a072ff383fa531a0b2ed4ebd9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:16:24 +0000 Subject: [PATCH 57/60] fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.10.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8312afaed3..6d11931de2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,6 +30,6 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=6.7.0.202309050840-r -VER_JUNIT=5.9.3 +VER_JUNIT=5.10.0 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From 59fce9599d67ce21cc710e100ca1a8010d3220c7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:14:33 +0000 Subject: [PATCH 58/60] chore(deps): update actions/checkout action to v4 --- .github/workflows/changelog-print.yml | 2 +- .github/workflows/ci.yml | 4 ++-- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/gradle-wrapper-validation.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index a3009e3a39..31b6c9aabc 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest name: changelogPrint steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: jdk 11 uses: actions/setup-java@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a8078339d..b6a2e612aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: buildcachepass: ${{ secrets.BUILDCACHE_PASS }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install JDK 11 @@ -59,7 +59,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} uses: actions/setup-java@v3 with: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b2f2a259c3..7fb9daff0d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f139032cf6..0e36087855 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: jdk 11 uses: actions/setup-java@v3 with: diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 2c02ce0fc4..d8be29afda 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -19,5 +19,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: gradle/wrapper-validation-action@v1 From 3562e49ef862e53678fdc02fd3280d5a4f249fb9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 09:19:51 -0700 Subject: [PATCH 59/60] Bump solstice to latest. --- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 22ba268426..2d62e25355 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -117,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception { } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.3.1"); + mavenDeps.add("dev.equo.ide:solstice:1.7.3"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From 6271c51fd85f4450e0cc0a0c7faa2a0f4e976ca6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 10:22:05 -0700 Subject: [PATCH 60/60] Fix findbugs warnings. --- .../src/main/java/com/diffplug/spotless/extra/P2Mirror.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java index f6ce6727b2..172857422b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.extra; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressFBWarnings("UWF_UNWRITTEN_FIELD") public class P2Mirror { private String prefix;