diff --git a/CHANGES.md b/CHANGES.md index 4ae906081b..f49f92c98c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Bump default `gherkin-utils` version `10.0.0` -> `12.0.2`. ([#2979](https://github.com/diffplug/spotless/pull/2979)) ### Fixed +* `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `VersionCatalogStep` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) - `VersionCatalogStep` preserves entries when comments contain unmatched brackets, preserves commas inside quoted strings, and keeps significant line boundaries in multiline entries. ([#3042](https://github.com/diffplug/spotless/pull/3042)) - `VersionCatalogStep` now reports unfinished entries as lints at their starting line. These fail formatting by default, so upgrading may expose catalog errors that previously caused silent data loss. ([#3042](https://github.com/diffplug/spotless/pull/3042)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 93abd770ec..1405d0d139 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - We no longer publish a plugin marker for the legacy `com.diffplug.gradle.spotless` id, which has been redirecting to `com.diffplug.spotless` since 4.0. Builds that still request it now fail with `Plugin [id: 'com.diffplug.gradle.spotless'] was not found` instead of the migration message. ([#3086](https://github.com/diffplug/spotless/pull/3086)) ### Fixed +* `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `versionCatalog()` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) - `versionCatalog()` preserves entries when comments contain unmatched brackets, preserves commas inside quoted strings, and keeps significant line boundaries in multiline entries. ([#3042](https://github.com/diffplug/spotless/pull/3042)) - `versionCatalog()` now reports unfinished entries as lints at their starting line. These fail formatting by default, so upgrading may expose catalog errors that previously caused silent data loss. ([#3042](https://github.com/diffplug/spotless/pull/3042)) 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 0d5838c24a..a05fc44eeb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2025 DiffPlug + * Copyright 2016-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -170,7 +170,7 @@ protected FormatterStep createStep() { private void fixParserToTypescript() { if (this.prettierConfig == null) { this.prettierConfig = new TreeMap<>(Map.of("parser", "typescript")); - } else { + } else if (!Objects.equals(this.prettierConfig.get("parser"), "typescript")) { final Object replaced = this.prettierConfig.put("parser", "typescript"); if (replaced != null) { getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", 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 0882d0f944..9f1988a624 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import java.io.IOException; +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -209,4 +211,49 @@ void useEslintStandardWithTypescriptRules() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } + + @Test + void prettierDoesNotWarnWhenTypescriptParserIsAlreadySet() throws IOException { + setFile(".prettierrc.json").toContent("{}"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " prettier().npmInstallCache().configFile('.prettierrc.json')", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/filetypes/typescript/typescript.dirty"); + + BuildResult result = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + + Assertions.assertThat(result.getOutput()) + .doesNotContain("overriding parser option to 'typescript'. Was set to 'typescript'"); + assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); + } + + @Test + void prettierWarnsWhenOverridingNonTypescriptParser() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " prettier().config(['parser': 'babel'])", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/filetypes/typescript/typescript.dirty"); + + BuildResult result = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + + Assertions.assertThat(result.getOutput()) + .contains("overriding parser option to 'typescript'. Was set to 'babel'"); + assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); + } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 96adf0d495..7d2e2a139f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Bump default `gherkin-utils` version `10.0.0` -> `12.0.2`. ([#2979](https://github.com/diffplug/spotless/pull/2979)) ### Fixed +* `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) - `` preserves entries when comments contain unmatched brackets, preserves commas inside quoted strings, and keeps significant line boundaries in multiline entries. ([#3042](https://github.com/diffplug/spotless/pull/3042)) - `` now reports unfinished entries as lints at their starting line. These fail formatting by default, so upgrading may expose catalog errors that previously caused silent data loss. ([#3042](https://github.com/diffplug/spotless/pull/3042))