diff --git a/CHANGES.md b/CHANGES.md index dd89d2c5bd..6e6da03181 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] +### Changes +* Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) ## [2.42.0] - 2023-09-28 ### Added 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..4aca4da02e 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,7 +36,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "1.0.0"; + private static final String DEFAULT_VERSION = "1.0.1"; 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:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 74f889fc04..8e803eacf1 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] +### Changes +* Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) ## [6.22.0] - 2023-09-28 ### Added 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..7ce1819d60 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 @@ -105,6 +105,42 @@ void testWithInvalidEditorConfigFile() throws IOException { assertThat(buildOutput).contains(invalidPath); } + @Test + void testReadCodeStyleFromEditorConfigFile() throws IOException { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint()", + " }", + "}"); + checkKtlintOfficialStyle(); + } + + @Test + void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { + setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().editorConfigOverride([", + " ktlint_code_style: \"ktlint_official\",", + " ])", + " }", + "}"); + checkKtlintOfficialStyle(); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( @@ -144,4 +180,11 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } + + private void checkKtlintOfficialStyle() throws IOException { + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); + } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d86096ab05..b2c84be366 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 `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) ### Added * CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) 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 060e0de84f..2916e118a5 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 @@ -44,4 +44,29 @@ void testKtlintEditorConfigOverride() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } + + @Test + void testReadCodeStyleFromEditorConfigFile() throws Exception { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + writePomWithKotlinSteps(""); + checkKtlintOfficialStyle(); + } + + @Test + void testSetEditorConfigCanOverrideEditorConfigFile() throws Exception { + setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); + writePomWithKotlinSteps("\n" + + " \n" + + " ktlint_official\n" + + " \n" + + ""); + checkKtlintOfficialStyle(); + } + + private void checkKtlintOfficialStyle() throws Exception { + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); + } } diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean new file mode 100644 index 0000000000..2466bb93fc --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean @@ -0,0 +1,6 @@ +fun main() { + val list = + listOf( + "hello", + ) +} diff --git a/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig b/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig new file mode 100644 index 0000000000..9efc62a854 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ktlint_code_style = intellij_idea diff --git a/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig b/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig new file mode 100644 index 0000000000..93a01f2e59 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ktlint_code_style = ktlint_official