Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
* **BREAKING** default `ktlint` editorconfig `ktlint_code_style` changed from `intellij_idea` to `ktlint_official` to better match the ktlint docs. ([#2090](https://github.com/diffplug/spotless/pull/2090))
- to keep the previous behavior of `intellij_idea`, you must set `ktlint_code_style = intellij_idea` in [.editconfig file](https://pinterest.github.io/ktlint/1.2.1/rules/code-styles/) or ```.editorConfigOverride(
mapOf("ktlint_code_style" to "intellij_idea"))```
### Removed
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ private static EditorConfigOverride createEditorConfigOverride(final List<Rule>
.distinct()
.collect(Collectors.toMap(EditorConfigProperty::getName, property -> property));

// The default style had been changed from intellij_idea to ktlint_official in version 1.0.0
if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) {
editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea");
}

// Create config properties based on provided property names and values
@SuppressWarnings("unchecked")
Pair<EditorConfigProperty<?>, ?>[] properties = editorConfigOverrideMap.entrySet().stream()
Expand Down
3 changes: 3 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
* **BREAKING** default `ktlint` editorconfig `ktlint_code_style` changed from `intellij_idea` to `ktlint_official` to better match the ktlint docs. ([#2090](https://github.com/diffplug/spotless/pull/2090))
- to keep the previous behavior of `intellij_idea`, you must set `ktlint_code_style = intellij_idea` in [.editconfig file](https://pinterest.github.io/ktlint/1.2.1/rules/code-styles/) or ```.editorConfigOverride(
mapOf("ktlint_code_style" to "intellij_idea"))```
### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
* Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import org.junit.jupiter.api.Test;

/**
* Unit test for {@link KotlinExtension}
*/
class KotlinExtensionTest extends GradleIntegrationHarness {
private static final String HEADER = "// License Header";
private static final String HEADER_WITH_YEAR = "// License Header $YEAR";
Expand Down Expand Up @@ -68,7 +71,7 @@ void integrationKtfmtDropboxStyleWithPublicApi() throws IOException {
}

@Test
void withExperimentalEditorConfigOverride() throws IOException {
void editorConfigOverride_setExperimental_intellijIdeaStyle() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'org.jetbrains.kotlin.jvm' version '1.6.21'",
Expand All @@ -79,6 +82,7 @@ void withExperimentalEditorConfigOverride() throws IOException {
" kotlin {",
" ktlint().editorConfigOverride([",
" ktlint_experimental: \"enabled\",",
" ktlint_code_style : \"intellij_idea\",",
" ij_kotlin_allow_trailing_comma: true,",
" ij_kotlin_allow_trailing_comma_on_call_site: true",
" ])",
Expand All @@ -89,6 +93,28 @@ void withExperimentalEditorConfigOverride() throws IOException {
assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean");
}

@Test
void editorConfigOverride_setExperimental_defaultKtlintOfficialStyle() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'org.jetbrains.kotlin.jvm' version '1.6.21'",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" kotlin {",
" ktlint().editorConfigOverride([",
" ktlint_experimental: \"enabled\",",
" ij_kotlin_allow_trailing_comma: true,",
" ij_kotlin_allow_trailing_comma_on_call_site: true",
" ])",
" }",
"}");
setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
}

@Test
void testWithInvalidEditorConfigFile() throws IOException {
String invalidPath = "invalid/path/to/.editorconfig".replace('/', File.separatorChar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class KotlinGradleExtensionTest extends KotlinExtensionTest {

@ParameterizedTest
@ValueSource(booleans = {true, false})
void testTarget(boolean useDefaultTarget) throws IOException {
void target_setAndUnset_intellijIdeaStyle(boolean useDefaultTarget) throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'org.jetbrains.kotlin.jvm' version '1.6.21'",
Expand All @@ -39,6 +39,7 @@ void testTarget(boolean useDefaultTarget) throws IOException {
" " + (useDefaultTarget ? "" : "target \"*.kts\""),
" ktlint().editorConfigOverride([",
" ktlint_experimental: \"enabled\",",
" ktlint_code_style: \"intellij_idea\",",
" ij_kotlin_allow_trailing_comma: true,",
" ij_kotlin_allow_trailing_comma_on_call_site: true",
" ])",
Expand All @@ -55,4 +56,35 @@ void testTarget(boolean useDefaultTarget) throws IOException {
assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean");
}
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void target_setAndUnset_defaultKtlintOfficialStyle(boolean useDefaultTarget) throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'org.jetbrains.kotlin.jvm' version '1.6.21'",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" kotlinGradle {",
" " + (useDefaultTarget ? "" : "target \"*.kts\""),
" ktlint().editorConfigOverride([",
" ktlint_experimental: \"enabled\",",
" ij_kotlin_allow_trailing_comma: true,",
" ij_kotlin_allow_trailing_comma_on_call_site: true",
" ])",
" }",
"}");
setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
setFile("configuration.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
gradleRunner().withArguments("spotlessApply").build();
if (useDefaultTarget) {
assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
} else {
assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
}
}
}
3 changes: 3 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
* Bump default `ktlint` version to latest `1.1.1` -> `1.2.1`. ([#2057](https://github.com/diffplug/spotless/pull/2057))
* Bump default `sortpom` version to latest `3.4.0` -> `3.4.1`. ([#2078](https://github.com/diffplug/spotless/pull/2078))
* **BREAKING** default `ktlint` editorconfig `ktlint_code_style` changed from `intellij_idea` to `ktlint_official` to better match the ktlint docs. ([#2090](https://github.com/diffplug/spotless/pull/2090))
- to keep the previous behavior of `intellij_idea`, you must set `ktlint_code_style = intellij_idea` in [.editconfig file](https://pinterest.github.io/ktlint/1.2.1/rules/code-styles/) or ```.editorConfigOverride(
mapOf("ktlint_code_style" to "intellij_idea"))```
### Added
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
* Skip execution in M2E (incremental) builds by default ([#1814](https://github.com/diffplug/spotless/issues/1814), [#2037](https://github.com/diffplug/spotless/issues/2037))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.diffplug.spotless.ProcessRunner;
import com.diffplug.spotless.maven.MavenIntegrationHarness;

/**
* Unit test for {@link Ktlint}
*/
class KtlintTest extends MavenIntegrationHarness {
@Test
void testKtlint() throws Exception {
Expand All @@ -34,18 +37,30 @@ void testKtlint() throws Exception {
}

@Test
void testKtlintEditorConfigOverride() throws Exception {
void writePomWithKotlinSteps_intellijIdea_intellijIdeaStyleKtlint() throws Exception {
writePomWithKotlinSteps("<ktlint>\n" +
" <editorConfigOverride>\n" +
" <ktlint_code_style>intellij_idea</ktlint_code_style>" +
" <ij_kotlin_allow_trailing_comma>true</ij_kotlin_allow_trailing_comma>\n" +
" <ij_kotlin_allow_trailing_comma_on_call_site>true</ij_kotlin_allow_trailing_comma_on_call_site>\n" +
" </editorConfigOverride>\n" +
"</ktlint>");

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.clean");
}
@Test
void writePomWithKotlinSteps_default_officialStyleKtlint() throws Exception {
writePomWithKotlinSteps("<ktlint>\n" +
" <editorConfigOverride>\n" +
" <ij_kotlin_allow_trailing_comma>true</ij_kotlin_allow_trailing_comma>\n" +
" <ij_kotlin_allow_trailing_comma_on_call_site>true</ij_kotlin_allow_trailing_comma_on_call_site>\n" +
" </editorConfigOverride>\n" +
"</ktlint>");

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.clean");
checkKtlintOfficialStyle();
}

@Test
Expand Down