Skip to content

Commit 8594c93

Browse files
authored
feat: ktlint editorConfigOverrides for plugin-maven (#1335 implements #1334)
2 parents be01e3b + 59c166a commit 8594c93

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334))
68

79
## [2.26.0] - 2022-09-14
810
### Added

plugin-maven/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T
359359
```xml
360360
<ktlint>
361361
<version>0.43.2</version> <!-- optional -->
362+
<editorConfigOverride> <!-- optional -->
363+
<ij_kotlin_allow_trailing_comma>true</ij_kotlin_allow_trailing_comma>
364+
<ij_kotlin_allow_trailing_comma_on_call_site>true</ij_kotlin_allow_trailing_comma_on_call_site>
365+
</editorConfigOverride>
362366
</ktlint>
363367
```
364368

plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,10 @@
1515
*/
1616
package com.diffplug.spotless.maven.kotlin;
1717

18+
import java.util.Collections;
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
1822
import org.apache.maven.plugins.annotations.Parameter;
1923

2024
import com.diffplug.spotless.FormatterStep;
@@ -27,9 +31,17 @@ public class Ktlint implements FormatterStepFactory {
2731
@Parameter
2832
private String version;
2933

34+
@Parameter
35+
private Map<String, Object> editorConfigOverride;
36+
3037
@Override
3138
public FormatterStep newFormatterStep(FormatterStepConfig config) {
3239
String ktlintVersion = version != null ? version : KtLintStep.defaultVersion();
33-
return KtLintStep.create(ktlintVersion, config.getProvisioner());
40+
41+
if (editorConfigOverride == null) {
42+
editorConfigOverride = new HashMap<>();
43+
}
44+
45+
return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride);
3446
}
3547
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ void testKtlint() throws Exception {
2929
mavenRunner().withArguments("spotless:apply").runNoError();
3030
assertFile(path).sameAsResource("kotlin/ktlint/basic.clean");
3131
}
32+
33+
@Test
34+
void testKtlintEditorConfigOverride() throws Exception {
35+
writePomWithKotlinSteps("<ktlint><editorConfigOverride><ij_kotlin_allow_trailing_comma>true</ij_kotlin_allow_trailing_comma><ij_kotlin_allow_trailing_comma_on_call_site>true</ij_kotlin_allow_trailing_comma_on_call_site></editorConfigOverride></ktlint>");
36+
37+
String path = "src/main/kotlin/Main.kt";
38+
setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
39+
mavenRunner().withArguments("spotless:apply").runNoError();
40+
assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean");
41+
}
3242
}

0 commit comments

Comments
 (0)