From 1dd92dae300aa59af0f640467cf6757898df9acf Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 14:31:04 +0200 Subject: [PATCH 01/19] chore: bump default eslint version --- .../com/diffplug/spotless/npm/EslintFormatterStep.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index a4480fe7fc..cee51b8518 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -47,7 +47,7 @@ public class EslintFormatterStep { public static final String NAME = "eslint-format"; - public static final String DEFAULT_ESLINT_VERSION = "^8.31.0"; + public static final String DEFAULT_ESLINT_VERSION = "^8.45.0"; public static Map defaultDevDependenciesForTypescript() { return defaultDevDependenciesTypescriptWithEslint(DEFAULT_ESLINT_VERSION); @@ -55,9 +55,9 @@ public static Map defaultDevDependenciesForTypescript() { public static Map defaultDevDependenciesTypescriptWithEslint(String eslintVersion) { Map dependencies = new LinkedHashMap<>(); - dependencies.put("@typescript-eslint/eslint-plugin", "^5.47.0"); - dependencies.put("@typescript-eslint/parser", "^5.47.0"); - dependencies.put("typescript", "^4.9.4"); + dependencies.put("@typescript-eslint/eslint-plugin", "^6.1.0"); + dependencies.put("@typescript-eslint/parser", "^6.1.0"); + dependencies.put("typescript", "^5.1.6"); dependencies.put("eslint", Objects.requireNonNull(eslintVersion)); return dependencies; } From e4c9bc8ea3bb4741e3e96b0256b2318097853c9e Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 14:32:46 +0200 Subject: [PATCH 02/19] chore: bump eslint styleguide versions This fixes #1756 --- .../gradle/spotless/TypescriptExtensionTest.java | 2 -- .../diffplug/spotless/npm/EslintStyleGuide.java | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index eaf2729296..9b4ec8372e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,7 +17,6 @@ import java.io.IOException; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.npm.EslintFormatterStep; @@ -170,7 +169,6 @@ void useEslint() throws IOException { } @Test - @Disabled("https://github.com/diffplug/spotless/issues/1756") void useEslintXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java index 62d0b0aa00..ad5cb2ba2e 100644 --- a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java @@ -29,9 +29,9 @@ public enum EslintStyleGuide { @Override public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-config-standard-with-typescript", "^36.1.0"); + dependencies.put("eslint-plugin-import", "^2.27.5"); + dependencies.put("eslint-plugin-n", "^16.0.1"); dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } @@ -41,7 +41,7 @@ public enum EslintStyleGuide { public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-xo", "^0.43.1"); - dependencies.put("eslint-config-xo-typescript", "^0.55.1"); + dependencies.put("eslint-config-xo-typescript", "^1.0.0"); return dependencies; } }, @@ -50,7 +50,7 @@ public enum EslintStyleGuide { public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-airbnb-base", "^15.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-import", "^2.27.5"); return dependencies; } }, @@ -66,9 +66,9 @@ public enum EslintStyleGuide { @Override public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard", "^17.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-config-standard", "^17.1.0"); + dependencies.put("eslint-plugin-import", "^2.27.5"); + dependencies.put("eslint-plugin-n", "^16.0.1"); dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } From ccbbd4c3224b224cb254e5fa42f490675601b09e Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 14:39:05 +0200 Subject: [PATCH 03/19] docs: add changed eslint version info --- CHANGES.md | 4 ++++ plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index cc6dcd7331..7da7e20ef3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,10 @@ 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] +### Fixed +* Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#9999](https://github.com/diffplug/spotless/pull/9999), [#1756](https://github.com/diffplug/spotless/issues/1756)) +### Changes +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [2.40.0] - 2023-07-17 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6d8bee7169..dfaaab678f 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] - +### Changes +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [6.20.0] - 2023-07-17 ### Added * Add target option `targetExcludeIfContentContains` and `targetExcludeIfContentContainsRegex` to exclude files based on their text content. ([#1749](https://github.com/diffplug/spotless/pull/1749)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 72d40dfe10..06f47866e6 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] +### Changes +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [2.38.0] - 2023-07-17 ### Added From 6afb6110257124933e8653e8eb4f32c09e302a01 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 14:40:37 +0200 Subject: [PATCH 04/19] docs: adapt for actual pr number --- CHANGES.md | 4 ++-- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7da7e20ef3..4ac5063b70 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,9 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#9999](https://github.com/diffplug/spotless/pull/9999), [#1756](https://github.com/diffplug/spotless/issues/1756)) +* 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)) ### Changes -* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) ## [2.40.0] - 2023-07-17 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index dfaaab678f..6057fe94ab 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) ## [6.20.0] - 2023-07-17 ### Added * Add target option `targetExcludeIfContentContains` and `targetExcludeIfContentContainsRegex` to exclude files based on their text content. ([#1749](https://github.com/diffplug/spotless/pull/1749)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 06f47866e6..75ee7a5b27 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761)) ## [2.38.0] - 2023-07-17 ### Added From 354a5828120b33db7380aea4c13a97695869fd84 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 09:42:25 +0200 Subject: [PATCH 05/19] chore: bump default prettier version to latest 2.x --- .../java/com/diffplug/spotless/npm/PrettierFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 11a6230e4c..7dcf38c314 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -42,7 +42,7 @@ public class PrettierFormatterStep { public static final String NAME = "prettier-format"; public static final Map defaultDevDependencies() { - return defaultDevDependenciesWithPrettier("2.8.1"); + return defaultDevDependenciesWithPrettier("2.8.8"); } public static final Map defaultDevDependenciesWithPrettier(String version) { From ca4136e421a5e01b2029cd173ad17793741962d8 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 09:48:23 +0200 Subject: [PATCH 06/19] feat: add support for prettier 3.x This fixes #1751 --- .../diffplug/spotless/npm/prettier-serve.js | 46 ++++++++++++------- .../npm/PrettierFormatterStepTest.java | 17 +++++-- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index b60daaaa77..ac1f26790d 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -1,15 +1,15 @@ const prettier = require("prettier"); app.post("/prettier/config-options", (req, res) => { - var config_data = req.body; - var prettier_config_path = config_data.prettier_config_path; - var prettier_config_options = config_data.prettier_config_options || {}; + const config_data = req.body; + const prettier_config_path = config_data.prettier_config_path; + const prettier_config_options = config_data.prettier_config_options || {}; if (prettier_config_path) { prettier .resolveConfig(undefined, { config: prettier_config_path }) .then(options => { - var mergedConfigOptions = mergeConfigOptions(options, prettier_config_options); + const mergedConfigOptions = mergeConfigOptions(options, prettier_config_options); res.set("Content-Type", "application/json") res.json(mergedConfigOptions); }) @@ -20,12 +20,12 @@ app.post("/prettier/config-options", (req, res) => { res.json(prettier_config_options); }); -app.post("/prettier/format", (req, res) => { - var format_data = req.body; +app.post("/prettier/format", async (req, res) => { + const format_data = req.body; - var formatted_file_content = ""; + let formatted_file_content = ""; try { - formatted_file_content = prettier.format(format_data.file_content, format_data.config_options); + formatted_file_content = await prettierFormat(format_data.file_content, format_data.config_options); } catch(err) { res.status(500).send("Error while formatting: " + err); return; @@ -34,7 +34,20 @@ app.post("/prettier/format", (req, res) => { res.send(formatted_file_content); }); -var mergeConfigOptions = function(resolved_config_options, config_options) { +const prettierFormat = async function(file_content, config_options) { + const result = prettier.format(file_content, config_options); + + // Check if result is a Promise (version 3.0.0 and above) + if (typeof result.then === 'function') { + return result; + } + + // If it's not a Promise (meaning it's a string), wrap it in a Promise (< 3.0.0) + return Promise.resolve(result); +} + + +const mergeConfigOptions = function(resolved_config_options, config_options) { if (resolved_config_options !== undefined && config_options !== undefined) { return extend(resolved_config_options, config_options); } @@ -46,15 +59,15 @@ var mergeConfigOptions = function(resolved_config_options, config_options) { } }; -var extend = function() { +const extend = function() { // Variables - var extended = {}; - var i = 0; - var length = arguments.length; + const extended = {}; + let i = 0; + const length = arguments.length; // Merge the object into the extended object - var merge = function(obj) { - for (var prop in obj) { + const merge = function (obj) { + for (const prop in obj) { if (Object.prototype.hasOwnProperty.call(obj, prop)) { extended[prop] = obj[prop]; } @@ -63,9 +76,8 @@ var extend = function() { // Loop through each object and conduct a merge for (; i < length; i++) { - var obj = arguments[i]; + const obj = arguments[i]; merge(obj); } - return extended; }; diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index c0e587aa98..a312e975d3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.util.Collections; +import java.util.Map; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -38,9 +39,19 @@ class PrettierFormatterStepTest extends ResourceHarness { @Nested class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { - @ParameterizedTest(name = "{index}: prettier can be applied to {0}") + @ParameterizedTest(name = "{index}: prettier 2.x can be applied to {0}") @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) - void formattingUsingConfigFile(String fileType) throws Exception { + void formattingUsingPrettier2WithConfigFile(String fileType) throws Exception { + runTestUsingPrettier(fileType, PrettierFormatterStep.defaultDevDependencies()); + } + + @ParameterizedTest(name = "{index}: prettier 3.x can be applied to {0}") + @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) + void formattingUsingPrettier3WithConfigFile(String fileType) throws Exception { + runTestUsingPrettier(fileType, ImmutableMap.of("prettier", "3.0.0")); + } + + private void runTestUsingPrettier(String fileType, Map dependencies) throws Exception { String filedir = "npm/prettier/filetypes/" + fileType + "/"; final File prettierRc = createTestFile(filedir + ".prettierrc.yml"); @@ -48,7 +59,7 @@ void formattingUsingConfigFile(String fileType) throws Exception { final String cleanFile = filedir + fileType + ".clean"; final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), + dependencies, TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 8187042d19a1a7593f42f28160be8515c3016227 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 11:49:32 +0200 Subject: [PATCH 07/19] fix: allow online-npm-install if prefer-offline fails This resolves #1750 --- .../com/diffplug/spotless/npm/NodeApp.java | 29 ++++++++++++++++++- .../NodeModulesCachingNpmProcessFactory.java | 4 +-- .../spotless/npm/NpmProcessException.java | 14 ++++++++- .../spotless/npm/NpmProcessFactory.java | 17 ++++++++++- .../npm/StandardNpmProcessFactory.java | 13 +++++---- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java index edac59bbfd..932a148626 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.npm; +import static com.diffplug.spotless.npm.NpmProcessFactory.OnlinePreferrence.PREFER_OFFLINE; +import static com.diffplug.spotless.npm.NpmProcessFactory.OnlinePreferrence.PREFER_ONLINE; + import java.util.Objects; import javax.annotation.Nonnull; @@ -22,6 +25,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.diffplug.spotless.ProcessRunner; + public class NodeApp { private static final Logger logger = LoggerFactory.getLogger(NodeApp.class); @@ -83,6 +88,28 @@ void prepareNodeAppLayout() { void npmInstall() { timedLogger.withInfo("Installing npm dependencies for {} with {}.", this.nodeServerLayout, this.npmProcessFactory.describe()) - .run(() -> npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations).waitFor()); + .run(this::optimizedNpmInstall); + } + + private void optimizedNpmInstall() { + try { + npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, PREFER_OFFLINE).waitFor(); + } catch (NpmProcessException e) { + if (!offlineInstallFailed(e.getResult())) { + throw e; // pass through + } + // if the npm install fails with message "No matching version found for @", we try again without the offline flag + npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, PREFER_ONLINE).waitFor(); + } + } + + private boolean offlineInstallFailed(ProcessRunner.Result result) { + if (result == null) { + return false; // no result, something else must have happened + } + if (result.exitCode() == 0) { + return false; // all is well + } + return result.stdOutUtf8().contains("code ETARGET") && result.stdOutUtf8().contains("No matching version found for"); // offline install failed, needs online install } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java index 0086064194..8a3af5fdf2 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -58,8 +58,8 @@ public static NodeModulesCachingNpmProcessFactory create(@Nonnull File cacheDir) } @Override - public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { - NpmProcess actualNpmInstallProcess = StandardNpmProcessFactory.INSTANCE.createNpmInstallProcess(nodeServerLayout, formatterStepLocations); + public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations, OnlinePreferrence onlinePreferrence) { + NpmProcess actualNpmInstallProcess = StandardNpmProcessFactory.INSTANCE.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, onlinePreferrence); return new CachingNmpInstall(actualNpmInstallProcess, nodeServerLayout); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java index bff621df07..33c6fb8d28 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java @@ -15,14 +15,26 @@ */ package com.diffplug.spotless.npm; +import javax.annotation.CheckForNull; + +import com.diffplug.spotless.ProcessRunner; + public class NpmProcessException extends RuntimeException { private static final long serialVersionUID = 6424331316676759525L; + private final ProcessRunner.Result result; - public NpmProcessException(String message) { + public NpmProcessException(String message, ProcessRunner.Result result) { super(message); + this.result = result; } public NpmProcessException(String message, Throwable cause) { super(message, cause); + this.result = null; + } + + @CheckForNull + public ProcessRunner.Result getResult() { + return result; } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java index 41543a2099..dbc9a807d5 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java @@ -16,7 +16,22 @@ package com.diffplug.spotless.npm; public interface NpmProcessFactory { - NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); + + enum OnlinePreferrence { + PREFER_OFFLINE("--prefer-offline"), PREFER_ONLINE("--prefer-online"); + + private final String option; + + OnlinePreferrence(String option) { + this.option = option; + } + + public String option() { + return option; + } + } + + NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations, OnlinePreferrence onlinePreferrence); NpmLongRunningProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java index 2c82768da2..91cf80ad69 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java @@ -32,8 +32,8 @@ private StandardNpmProcessFactory() { } @Override - public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { - return new NpmInstall(nodeServerLayout.nodeModulesDir(), formatterStepLocations); + public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations, OnlinePreferrence onlinePreferrence) { + return new NpmInstall(nodeServerLayout.nodeModulesDir(), formatterStepLocations, onlinePreferrence); } @Override @@ -80,8 +80,11 @@ public String doDescribe() { private static class NpmInstall extends AbstractStandardNpmProcess implements NpmProcess { - public NpmInstall(File workingDir, NpmFormatterStepLocations formatterStepLocations) { + private final OnlinePreferrence onlinePreferrence; + + public NpmInstall(File workingDir, NpmFormatterStepLocations formatterStepLocations, OnlinePreferrence onlinePreferrence) { super(workingDir, formatterStepLocations); + this.onlinePreferrence = onlinePreferrence; } @Override @@ -91,7 +94,7 @@ protected List commandLine() { "install", "--no-audit", "--no-fund", - "--prefer-offline"); + onlinePreferrence.option()); } @Override @@ -103,7 +106,7 @@ public String describe() { public ProcessRunner.Result waitFor() { try (ProcessRunner.LongRunningProcess npmProcess = doStart()) { if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + describe() + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); + throw new NpmProcessException("Running npm command '" + describe() + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result(), npmProcess.result()); } return npmProcess.result(); } catch (InterruptedException e) { From bd0918318703b9a51995fd2c893e19eefb2a494b Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 11:56:24 +0200 Subject: [PATCH 08/19] fix: adaptions for prettier 3 formatter-changes in html --- .../filetypes/html_prettier3/.prettierrc.yml | 1 + .../html_prettier3/html_prettier3.clean | 13 +++++++++++++ .../html_prettier3/html_prettier3.dirty | 17 +++++++++++++++++ .../spotless/npm/PrettierFormatterStepTest.java | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/.prettierrc.yml create mode 100644 testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.clean create mode 100644 testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.dirty diff --git a/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/.prettierrc.yml b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/.prettierrc.yml new file mode 100644 index 0000000000..f1185441f8 --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/.prettierrc.yml @@ -0,0 +1 @@ +parser: html diff --git a/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.clean b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.clean new file mode 100644 index 0000000000..385e636b7b --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.clean @@ -0,0 +1,13 @@ + + + + + Test + + + + + + + + diff --git a/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.dirty b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.dirty new file mode 100644 index 0000000000..35ed1e9d3b --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/filetypes/html_prettier3/html_prettier3.dirty @@ -0,0 +1,17 @@ + + + + + + Test + + + + + + + + + diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index a312e975d3..f359a1f463 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -46,7 +46,7 @@ void formattingUsingPrettier2WithConfigFile(String fileType) throws Exception { } @ParameterizedTest(name = "{index}: prettier 3.x can be applied to {0}") - @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) + @ValueSource(strings = {"html_prettier3", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) void formattingUsingPrettier3WithConfigFile(String fileType) throws Exception { runTestUsingPrettier(fileType, ImmutableMap.of("prettier", "3.0.0")); } From e6b2268501727c7932eae0e450acf4287fb17ddc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 13:27:03 +0200 Subject: [PATCH 09/19] chore: make sure to test prettier 3 also on configuration parts --- .../spotless/npm/PrettierFormatterStep.java | 4 +- .../npm/prettier/config/.prettierrc.yml | 2 +- .../typescript.configfile_prettier_2.clean | 18 ++++++++ .../typescript.configfile_prettier_3.clean | 18 ++++++++ ...n => typescript.defaults_prettier_2.clean} | 0 ...n => typescript.defaults_prettier_3.clean} | 2 +- ...n => typescript.override_prettier_2.clean} | 0 .../typescript.override_prettier_3.clean | 13 ++++++ .../npm/PrettierFormatterStepTest.java | 46 ++++++++++++------- 9 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_2.clean create mode 100644 testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_3.clean rename testlib/src/main/resources/npm/prettier/config/{typescript.defaults.clean => typescript.defaults_prettier_2.clean} (100%) rename testlib/src/main/resources/npm/prettier/config/{typescript.configfile.clean => typescript.defaults_prettier_3.clean} (92%) rename testlib/src/main/resources/npm/prettier/config/{typescript.override.clean => typescript.override_prettier_2.clean} (100%) create mode 100644 testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_3.clean diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 7dcf38c314..72fecded1f 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -41,8 +41,10 @@ public class PrettierFormatterStep { public static final String NAME = "prettier-format"; + public static final String DEFAULT_VERSION = "2.8.8"; + public static final Map defaultDevDependencies() { - return defaultDevDependenciesWithPrettier("2.8.8"); + return defaultDevDependenciesWithPrettier(DEFAULT_VERSION); } public static final Map defaultDevDependenciesWithPrettier(String version) { diff --git a/testlib/src/main/resources/npm/prettier/config/.prettierrc.yml b/testlib/src/main/resources/npm/prettier/config/.prettierrc.yml index f078267520..828586c801 100644 --- a/testlib/src/main/resources/npm/prettier/config/.prettierrc.yml +++ b/testlib/src/main/resources/npm/prettier/config/.prettierrc.yml @@ -1,2 +1,2 @@ parser: typescript -printWidth: 50 +printWidth: 20 diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_2.clean b/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_2.clean new file mode 100644 index 0000000000..451b5466a0 --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_2.clean @@ -0,0 +1,18 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements + DisposeAware, + CallbackAware +{ + public myValue: string[]; + + constructor( + private myService: Service, + name: string, + private field: any + ) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_3.clean b/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_3.clean new file mode 100644 index 0000000000..30d30f8595 --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/config/typescript.configfile_prettier_3.clean @@ -0,0 +1,18 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements + DisposeAware, + CallbackAware +{ + public myValue: string[]; + + constructor( + private myService: Service, + name: string, + private field: any, + ) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean b/testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_2.clean similarity index 100% rename from testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean rename to testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_2.clean diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean b/testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_3.clean similarity index 92% rename from testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean rename to testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_3.clean index dfe71bf0a9..9fa0eed3cc 100644 --- a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean +++ b/testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_3.clean @@ -7,7 +7,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary constructor( private myService: Service, name: string, - private field: any + private field: any, ) { super(name); } diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.override.clean b/testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_2.clean similarity index 100% rename from testlib/src/main/resources/npm/prettier/config/typescript.override.clean rename to testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_2.clean diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_3.clean b/testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_3.clean new file mode 100644 index 0000000000..c49cd544df --- /dev/null +++ b/testlib/src/main/resources/npm/prettier/config/typescript.override_prettier_3.clean @@ -0,0 +1,13 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor( + private myService: Service, + name: string, + private field: any, + ) { + super(name); + } + + //... +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index f359a1f463..672aec740b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -35,6 +35,10 @@ @NpmTest class PrettierFormatterStepTest extends ResourceHarness { + private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION; + + private static final String PRETTIER_VERSION_3 = "3.0.0"; + @NpmTest @Nested class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { @@ -77,15 +81,16 @@ private void runTestUsingPrettier(String fileType, Map dependenc @Nested class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests { - @Test - void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { + @ParameterizedTest(name = "{index}: parser inference based on explicit filepath is working with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void parserInferenceBasedOnExplicitFilepathIsWorking(String prettierVersion) throws Exception { String filedir = "npm/prettier/filetypes/json/"; final String dirtyFile = filedir + "json.dirty"; final String cleanFile = filedir + "json.clean"; final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), + ImmutableMap.of("prettier", prettierVersion), TestProvisioner.mavenCentral(), projectDir(), buildDir(), @@ -98,15 +103,16 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { } } - @Test - void parserInferenceBasedOnFilenameIsWorking() throws Exception { + @ParameterizedTest(name = "{index}: parser inference based on filename is working with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void parserInferenceBasedOnFilenameIsWorking(String prettierVersion) throws Exception { String filedir = "npm/prettier/filename/"; final String dirtyFile = filedir + "dirty.json"; final String cleanFile = filedir + "clean.json"; final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), + ImmutableMap.of("prettier", prettierVersion), TestProvisioner.mavenCentral(), projectDir(), buildDir(), @@ -142,13 +148,13 @@ class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests { private static final String FILEDIR = "npm/prettier/config/"; - void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception { + void runFormatTest(String prettierVersion, PrettierConfig config, String cleanFileNameSuffix) throws Exception { final String dirtyFile = FILEDIR + "typescript.dirty"; final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean"; final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), + ImmutableMap.of("prettier", prettierVersion), TestProvisioner.mavenCentral(), projectDir(), buildDir(), @@ -161,20 +167,26 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc } } - @Test - void defaultsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults"); + @ParameterizedTest(name = "{index}: defaults are applied with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void defaultsAreApplied(String prettierVersion) throws Exception { + runFormatTest(prettierVersion, new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults_prettier_" + major(prettierVersion)); } - @Test - void configFileOptionsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile"); + @ParameterizedTest(name = "{index}: config file options are applied with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void configFileOptionsAreApplied(String prettierVersion) throws Exception { + runFormatTest(prettierVersion, new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile_prettier_" + major(prettierVersion)); } - @Test - void configFileOptionsCanBeOverriden() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override"); + @ParameterizedTest(name = "{index}: config file options can be overriden with prettier {0}") + @ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3}) + void configFileOptionsCanBeOverriden(String prettierVersion) throws Exception { + runFormatTest(prettierVersion, new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override_prettier_" + major(prettierVersion)); } + private String major(String semVer) { + return semVer.split("\\.")[0]; + } } } From 4fac1e7e144d03a84fd7d53d53c328a5f076b8e9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 13:56:24 +0200 Subject: [PATCH 10/19] docs: adding changes and doc related to prettier --- CHANGES.md | 4 ++++ plugin-gradle/CHANGES.md | 3 +++ plugin-gradle/README.md | 1 + plugin-maven/CHANGES.md | 3 +++ plugin-maven/README.md | 1 + 5 files changed, 12 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cc6dcd7331..67cc01a40c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,11 +17,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) +* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750)) + ### Changes * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [2.39.0] - 2023-05-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6d8bee7169..658f65f420 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -18,11 +18,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( } } ``` +* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750)) ### Changes * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [6.19.0] - 2023-05-24 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index e04697766a..2334c3ff71 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -882,6 +882,7 @@ spotless { yaml { target 'src/**/*.yaml' // you have to set the target manually jackson() // has its own section below + prettier() // has its own section below } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 72d40dfe10..98655ba3fe 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,11 +9,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) +* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) +* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750)) ### Changes * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) ## [2.37.0] - 2023-05-24 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index c1ffd31e40..af32c092fd 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -970,6 +970,7 @@ Uses Jackson for formatting. + ``` From 41138c92343f823973b0c07ec4712a181138bc42 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 13:59:51 +0200 Subject: [PATCH 11/19] docs: adapt for actual PR number --- CHANGES.md | 6 +++--- plugin-gradle/CHANGES.md | 6 +++--- plugin-maven/CHANGES.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 67cc01a40c..00241182b0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,15 +17,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.39.0] - 2023-05-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 658f65f420..4358e9f26c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -18,14 +18,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( } } ``` -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [6.19.0] - 2023-05-24 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 98655ba3fe..823841a328 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,14 +9,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751)) -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.37.0] - 2023-05-24 ### Added From 7a4268b7e6768c072527432b160e00d071c36c57 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 14:50:25 +0200 Subject: [PATCH 12/19] fix: resolves spotbugs issue (serializability of exception) --- .../java/com/diffplug/spotless/npm/NpmProcessException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java index 33c6fb8d28..c2e8444bcc 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java @@ -21,7 +21,7 @@ public class NpmProcessException extends RuntimeException { private static final long serialVersionUID = 6424331316676759525L; - private final ProcessRunner.Result result; + private final transient ProcessRunner.Result result; public NpmProcessException(String message, ProcessRunner.Result result) { super(message); From a24908528cb3c7c35f3eee576814ce067bc60e7a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 15:01:42 +0200 Subject: [PATCH 13/19] docs: move to Unreleased --- CHANGES.md | 9 +++++---- plugin-gradle/CHANGES.md | 9 +++++---- plugin-maven/CHANGES.md | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 00241182b0..e54f6f6108 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,11 @@ 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] +### 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 `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.40.0] - 2023-07-17 ### Added @@ -17,15 +22,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) -* 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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.39.0] - 2023-05-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4358e9f26c..b2e3972bba 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### 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 `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [6.20.0] - 2023-07-17 ### Added @@ -18,15 +23,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( } } ``` -* 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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) - ## [6.19.0] - 2023-05-24 ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 823841a328..dcccd5d2ba 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,20 +3,22 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### 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 `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.38.0] - 2023-07-17 ### Added * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) -* 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 `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) * 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. -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760)) ## [2.37.0] - 2023-05-24 ### Added From 3577f4e2d4d42b7bf055067827e36194a984afef Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 15:27:13 +0200 Subject: [PATCH 14/19] fix: provide "lower" default versions for ts_standard as the upstream package has incompatible version restrictions otherwise --- .../main/java/com/diffplug/spotless/npm/EslintStyleGuide.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java index ad5cb2ba2e..cb6f1325df 100644 --- a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java @@ -29,7 +29,9 @@ public enum EslintStyleGuide { @Override public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "^36.1.0"); + dependencies.put("@typescript-eslint/eslint-plugin", "^5.62.0"); + dependencies.put("@typescript-eslint/parser", "^5.62.0"); + dependencies.put("eslint-config-standard-with-typescript", "^36.0.1"); dependencies.put("eslint-plugin-import", "^2.27.5"); dependencies.put("eslint-plugin-n", "^16.0.1"); dependencies.put("eslint-plugin-promise", "^6.1.1"); From 7be049efc08def31b0a3f98d75a9253e959da960 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 15:35:18 +0200 Subject: [PATCH 15/19] fix: adapt tests to work with newer prettier versions --- .../NpmTestsWithoutNpmInstallationTest.java | 16 ++++++++-------- ...ationTest_gradle_node_plugin_example_1.gradle | 2 +- ...ationTest_gradle_node_plugin_example_2.gradle | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 03d14292e9..363d88c0c0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -40,7 +40,7 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception { " npmWorkDir = file(\"${buildDir}/npm\")", "}", "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", + "prettierConfig['printWidth'] = 20", "prettierConfig['parser'] = 'typescript'", "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", @@ -59,7 +59,7 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception { // then run spotless using that node installation final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } catch (Exception e) { printContents(); throw e; @@ -79,7 +79,7 @@ void useNodeAndNpmFromNodeGradlePlugin_example1() throws Exception { 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.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } catch (Exception e) { printContents(); throw e; @@ -93,7 +93,7 @@ void useNpmFromNodeGradlePlugin_example2() throws Exception { 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.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } catch (Exception e) { printContents(); throw e; @@ -115,7 +115,7 @@ void useNpmFromNodeGradlePlugin() throws Exception { " workDir = file(\"${buildDir}/nodejs\")", "}", "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", + "prettierConfig['printWidth'] = 20", "prettierConfig['parser'] = 'typescript'", "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", "spotless {", @@ -132,7 +132,7 @@ void useNpmFromNodeGradlePlugin() throws Exception { // then run spotless using that node installation final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } catch (Exception e) { printContents(); throw e; @@ -154,7 +154,7 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { " workDir = file(\"${buildDir}/nodejs\")", "}", "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", + "prettierConfig['printWidth'] = 20", "prettierConfig['parser'] = 'typescript'", "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", "spotless {", @@ -171,7 +171,7 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { // then run spotless using that node installation final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } catch (Exception e) { printContents(); throw e; diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle index 7ec7a2c592..c5acf5bbc5 100644 --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle @@ -16,7 +16,7 @@ node { npmWorkDir = file("${buildDir}/npm") } def prettierConfig = [:] -prettierConfig['printWidth'] = 50 +prettierConfig['printWidth'] = 20 prettierConfig['parser'] = 'typescript' // the executable names diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle index eb59b85cf0..ef843a8475 100644 --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle @@ -14,7 +14,7 @@ node { workDir = file("${buildDir}/nodejs") } def prettierConfig = [:] -prettierConfig['printWidth'] = 50 +prettierConfig['printWidth'] = 20 prettierConfig['parser'] = 'typescript' // the executable name From aa4893b1942778c3d7b69dae89977cb0aba2b13c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 15:55:50 +0200 Subject: [PATCH 16/19] fix: create valid poms when using eslint styleguides (and enable the missed and disabled xo test in maven part) --- .../spotless/maven/typescript/TypescriptFormatStepTest.java | 2 -- .../main/java/com/diffplug/spotless/npm/EslintStyleGuide.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 911cfad201..a09111d30d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -19,7 +19,6 @@ import java.io.IOException; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.ProcessRunner; @@ -211,7 +210,6 @@ void eslintStyleguideStandardWithTypescript() throws Exception { } @Test - @Disabled("https://github.com/diffplug/spotless/issues/1756") void eslintStyleguideXo() throws Exception { writePomWithTypescriptSteps( TEST_FILE_PATH, diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java index cb6f1325df..874ae1905d 100644 --- a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java @@ -115,8 +115,8 @@ public String asGradleMapStringMergedWith(Map devDependencies) { public String asMavenXmlStringMergedWith(Map devDependencies) { return mergedWith(devDependencies).entrySet().stream() - .map(entry -> "<" + entry.getKey() + ">" + entry.getValue() + "") - .collect(Collectors.joining("", "", "")); + .map(entry -> String.format("%s%s", entry.getKey(), entry.getValue())) + .collect(Collectors.joining("", "", "")); } } From 217c56198d0997a62a56a38f6dfa6509085bed93 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 16:16:15 +0200 Subject: [PATCH 17/19] fix: adapt for prettier upgrades --- .../NpmInstallCacheIntegrationTests.java | 4 +- .../spotless/PrettierIntegrationTest.java | 24 +++++----- .../prettier/PrettierFormatStepTest.java | 12 ++--- .../npm/prettier/plugins/java-test.clean | 5 ++- .../resources/npm/prettier/plugins/php.clean | 44 +++++++++---------- .../npm/PrettierFormatterStepTest.java | 2 +- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java index 3a690fbc55..e7ad5f1654 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java @@ -112,8 +112,8 @@ private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOEx "prettierConfig['tabWidth'] = 3", "prettierConfig['parser'] = 'php'", "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.0.5'", - "prettierPackages['@prettier/plugin-php'] = '0.14.2'", + "prettierPackages['prettier'] = '2.8.8'", + "prettierPackages['@prettier/plugin-php'] = '0.19.6'", "spotless {", " format 'php', {", " target 'php-example.php'", 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 a6b2ea9dc8..4d5069c1b5 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 @@ -33,7 +33,7 @@ void useInlineConfig() throws IOException { "}", "repositories { mavenCentral() }", "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", + "prettierConfig['printWidth'] = 20", "prettierConfig['parser'] = 'typescript'", "spotless {", " format 'mytypescript', {", @@ -44,7 +44,7 @@ void useInlineConfig() throws IOException { 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.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } @Test @@ -88,7 +88,7 @@ void useFileConfig() throws IOException { 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.clean"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); } @Test @@ -121,8 +121,8 @@ void useJavaCommunityPlugin() throws IOException { "prettierConfig['tabWidth'] = 4", "prettierConfig['parser'] = 'java'", "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.0.5'", - "prettierPackages['prettier-plugin-java'] = '0.8.0'", + "prettierPackages['prettier'] = '2.8.8'", + "prettierPackages['prettier-plugin-java'] = '2.2.0'", "spotless {", " format 'java', {", " target 'JavaTest.java'", @@ -145,7 +145,7 @@ void suggestsMissingJavaCommunityPlugin() throws IOException { "def prettierConfig = [:]", "prettierConfig['tabWidth'] = 4", "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.0.5'", + "prettierPackages['prettier'] = '2.8.8'", "spotless {", " format 'java', {", " target 'JavaTest.java'", @@ -169,8 +169,8 @@ void usePhpCommunityPlugin() throws IOException { "prettierConfig['tabWidth'] = 3", "prettierConfig['parser'] = 'php'", "def prettierPackages = [:]", - "prettierPackages['prettier'] = '2.0.5'", - "prettierPackages['@prettier/plugin-php'] = '0.14.2'", + "prettierPackages['prettier'] = '2.8.8'", + "prettierPackages['@prettier/plugin-php'] = '0.19.6'", "spotless {", " format 'php', {", " target 'php-example.php'", @@ -199,14 +199,14 @@ void usePhpAndJavaCommunityPlugin() throws IOException { "prettierConfigPhp['tabWidth'] = 3", "prettierConfigPhp['parser'] = 'php'", "def prettierPackagesPhp = [:]", - "prettierPackagesPhp['prettier'] = '2.0.5'", - "prettierPackagesPhp['@prettier/plugin-php'] = '0.14.2'", + "prettierPackagesPhp['prettier'] = '2.8.8'", + "prettierPackagesPhp['@prettier/plugin-php'] = '0.19.6'", "def prettierConfigJava = [:]", "prettierConfigJava['tabWidth'] = 4", "prettierConfigJava['parser'] = 'java'", "def prettierPackagesJava = [:]", - "prettierPackagesJava['prettier'] = '2.0.5'", - "prettierPackagesJava['prettier-plugin-java'] = '0.8.0'", + "prettierPackagesJava['prettier'] = '2.8.8'", + "prettierPackagesJava['prettier-plugin-java'] = '2.2.0'", "spotless {", " format 'php', {", " target 'php-example.php'", 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 78a0fc30ff..9cd1a313eb 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 @@ -120,11 +120,11 @@ void multiple_prettier_configs() throws Exception { " ", " ", " prettier", - " 2.0.5", + " 2.8.8", " ", " ", " @prettier/plugin-php", - " 0.14.2", + " 0.19.6", " ", " ", " ", @@ -137,11 +137,11 @@ void multiple_prettier_configs() throws Exception { " ", " ", " prettier", - " 2.0.5", + " 2.8.8", " ", " ", " prettier-plugin-java", - " 0.8.0", + " 2.2.0", " ", " ", " ", @@ -166,11 +166,11 @@ void custom_plugin() throws Exception { " ", " ", " prettier", - " 2.0.5", + " 2.8.8", " ", " ", " @prettier/plugin-php", - " 0.14.2", + " 0.19.6", " ", " ", " ", diff --git a/testlib/src/main/resources/npm/prettier/plugins/java-test.clean b/testlib/src/main/resources/npm/prettier/plugins/java-test.clean index c45ffe5183..93cf43955f 100644 --- a/testlib/src/main/resources/npm/prettier/plugins/java-test.clean +++ b/testlib/src/main/resources/npm/prettier/plugins/java-test.clean @@ -4,6 +4,7 @@ import java.util.List; import java.util.function.Consumer; public class JavaTest { + private static final String NAME = "JavaTest"; private List strings = new ArrayList<>(); @@ -30,8 +31,8 @@ public class JavaTest { JavaTest javaTest = new JavaTest("1", "2", "3"); System.out.println("joined: " + javaTest.join(',')); StringBuilder builder = new StringBuilder(); - javaTest.operateOn( - strings -> builder.append(String.join("---", strings)) + javaTest.operateOn(strings -> + builder.append(String.join("---", strings)) ); } } diff --git a/testlib/src/main/resources/npm/prettier/plugins/php.clean b/testlib/src/main/resources/npm/prettier/plugins/php.clean index 4c8710bbee..067647a029 100644 --- a/testlib/src/main/resources/npm/prettier/plugins/php.clean +++ b/testlib/src/main/resources/npm/prettier/plugins/php.clean @@ -27,17 +27,17 @@ abstract class ReallyReallyReallyLongClassName // variable doc public $test; public $other = 1; - public static $staticTest = ['hi']; + public static $staticTest = ["hi"]; static $cache; protected static $_instance; - protected $fillable = ['title', 'requester_id', 'type', 'summary', 'proof']; + protected $fillable = ["title", "requester_id", "type", "summary", "proof"]; protected $fillable2 = [ - 'title', - 'description', - 'requester_id', - 'type', - 'summary', - 'proof', + "title", + "description", + "requester_id", + "type", + "summary", + "proof", ]; protected $test = [ //test @@ -52,7 +52,7 @@ abstract class ReallyReallyReallyLongClassName * * @return \Some\Test */ - public function __construct($test, $test_int = null, $test_string = 'hi') + public function __construct($test, $test_int = null, $test_string = "hi") { parent::__construct($test_int ?: 1); $this->other = $test_string; @@ -108,7 +108,7 @@ abstract class ReallyReallyReallyLongClassName public function returnTypeTest(): string { - return 'hi'; + return "hi"; } final public static function bar() @@ -125,17 +125,17 @@ abstract class ReallyReallyReallyLongClassName public function method1() { - return 'hi'; + return "hi"; } public function method2() { - return 'hi'; + return "hi"; } public function method3() { - return 'hi'; + return "hi"; } public function testReturn(?string $name): ?string @@ -164,7 +164,7 @@ abstract class ReallyReallyReallyLongClassName string $bar, int $baz ): string { - return 'foo'; + return "foo"; } public function longLongAnotherFunctionOther( @@ -172,7 +172,7 @@ abstract class ReallyReallyReallyLongClassName string $bar, int $baz ) { - return 'foo'; + return "foo"; } public function testReturnTypeDeclaration(): object @@ -297,13 +297,13 @@ class field extends \models\base { protected function pre_save($input, $fields) { - $input['configs'] = json_encode( + $input["configs"] = json_encode( array_merge( $configs, - $field_type->process_field_config_from_user($input['definition']) + $field_type->process_field_config_from_user($input["definition"]) ) ); - unset($input['definition']); + unset($input["definition"]); } } @@ -311,8 +311,8 @@ class test { public function test_method() { - $customer = (object) ['name' => 'Bob']; - $job = (object) ['customer' => $customer]; + $customer = (object) ["name" => "Bob"]; + $job = (object) ["customer" => $customer]; return "The customer for that job, {$job->customer->name} has an error that shows up after the line gets waaaaay toooo long."; } @@ -488,9 +488,9 @@ class User { public int $id; public string $name; - public ?string $b = 'foo'; + public ?string $b = "foo"; private Foo $prop; - protected static string $static = 'default'; + protected static string $static = "default"; public function __construct(int $id, string $name) { diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 672aec740b..769d91bc01 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -128,7 +128,7 @@ void parserInferenceBasedOnFilenameIsWorking(String prettierVersion) throws Exce @Test void verifyPrettierErrorMessageIsRelayed() throws Exception { FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), + PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.8.8"), TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 6188a820f5ca18dd375164ccbcadc8a5a2f9e621 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 16:16:28 +0200 Subject: [PATCH 18/19] docs: adapt for newer base versions --- plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2334c3ff71..3484e3cd59 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -979,11 +979,11 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos ```gradle spotless { java { - prettier(['prettier': '2.0.5', 'prettier-plugin-java': '0.8.0']).config(['parser': 'java', 'tabWidth': 4]) + prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4]) } format 'php', { target 'src/**/*.php' - prettier(['prettier': '2.0.5', '@prettier/plugin-php': '0.14.2']).config(['parser': 'php', 'tabWidth': 3]) + prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3]) } } ``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index af32c092fd..62f2a4ea57 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1047,11 +1047,11 @@ You can use prettier in any language-specific format, but usually you will be cr prettier - 2.0.5 + 2.8.8 @prettier/plugin-php - 0.14.2 + 0.19.6 @@ -1097,8 +1097,8 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos - 2.0.5 - 0.8.0 + 2.8.8 + 2.2.0 4 @@ -1118,11 +1118,11 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos prettier - 2.0.5 + 2.8.8 @prettier/plugin-php - 0.14.2 + 0.19.6 From b4a118a41e8d0244d80c249bdcb74c9557c0f57c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 18 Jul 2023 17:21:48 +0200 Subject: [PATCH 19/19] fix: upgrade to newer npm version for maybe fixing windows build --- .../gradle/spotless/NpmTestsWithoutNpmInstallationTest.java | 6 +++--- ...tNpmInstallationTest_gradle_node_plugin_example_1.gradle | 4 ++-- ...tNpmInstallationTest_gradle_node_plugin_example_2.gradle | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 363d88c0c0..d01d1ab006 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -34,8 +34,8 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception { "repositories { mavenCentral() }", "node {", " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", + " version = '18.16.1'", + " npmVersion = '9.5.1'", " workDir = file(\"${buildDir}/nodejs\")", " npmWorkDir = file(\"${buildDir}/npm\")", "}", @@ -111,7 +111,7 @@ void useNpmFromNodeGradlePlugin() throws Exception { "repositories { mavenCentral() }", "node {", " download = true", - " version = '18.13.0'", + " version = '18.16.1'", " workDir = file(\"${buildDir}/nodejs\")", "}", "def prettierConfig = [:]", diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle index c5acf5bbc5..c0fa255bcc 100644 --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle @@ -9,8 +9,8 @@ plugins { repositories { mavenCentral() } node { download = true - version = '18.13.0' - npmVersion = '8.19.2' + version = '18.16.1' + npmVersion = '9.5.1' // when setting both these directories, npm and node will be in separate directories workDir = file("${buildDir}/nodejs") npmWorkDir = file("${buildDir}/npm") diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle index ef843a8475..6d77bc3d69 100644 --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle @@ -9,7 +9,7 @@ plugins { repositories { mavenCentral() } node { download = true - version = '18.13.0' + version = '18.16.1' // when not setting an explicit `npmWorkDir`, the npm binary will be installed next to the node binary workDir = file("${buildDir}/nodejs") }