Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ktlint editorConfigOverrides for plugin-maven #1335

Merged
merged 4 commits into from
Sep 19, 2022
Merged
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
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
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");
}
}