diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1ce37116a1..6046e7aed1 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] +### Added +* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.26.0] - 2022-09-14 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 19796770ef..a6a8491784 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -359,6 +359,10 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml 0.43.2 + + true + true + ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 796523d315..45bda05065 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,10 @@ */ package com.diffplug.spotless.maven.kotlin; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; @@ -27,9 +31,17 @@ public class Ktlint implements FormatterStepFactory { @Parameter private String version; + @Parameter + private Map editorConfigOverride; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); - return KtLintStep.create(ktlintVersion, config.getProvisioner()); + + if (editorConfigOverride == null) { + editorConfigOverride = new HashMap<>(); + } + + return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride); } } 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 887f7a3f50..ba6f1d8e2c 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 @@ -29,4 +29,14 @@ void testKtlint() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/basic.clean"); } + + @Test + void testKtlintEditorConfigOverride() throws Exception { + writePomWithKotlinSteps("truetrue"); + + 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"); + } }