Skip to content

Commit

Permalink
feat: ktlint editorConfigOverrides for plugin-maven (#1335 implements #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Sep 19, 2022
2 parents be01e3b + 59c166a commit 8594c93
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugin-maven/README.md
Expand Up @@ -359,6 +359,10 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T
```xml
<ktlint>
<version>0.43.2</version> <!-- optional -->
<editorConfigOverride> <!-- optional -->
<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>
```

Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -27,9 +31,17 @@ public class Ktlint implements FormatterStepFactory {
@Parameter
private String version;

@Parameter
private Map<String, Object> 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);
}
}
Expand Up @@ -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("<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>");

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");
}
}

0 comments on commit 8594c93

Please sign in to comment.