Skip to content

Commit 0be12f5

Browse files
committed
Default EditorConfig path to ".editorconfig" in plugin-maven ktlint step
The default path was never set, which means that .editorconfig was never picked up if not explicitly set.
1 parent cf6c76f commit 0be12f5

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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,7 @@
1515
*/
1616
package com.diffplug.spotless.maven.kotlin;
1717

18+
import java.io.File;
1819
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.List;
@@ -43,6 +44,12 @@ public class Ktlint implements FormatterStepFactory {
4344
public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) {
4445
String ktlintVersion = version != null ? version : KtLintStep.defaultVersion();
4546
FileSignature configPath = null;
47+
if (editorConfigPath == null) {
48+
File defaultEditorConfig = new File(".editorconfig");
49+
if (defaultEditorConfig.exists()) {
50+
editorConfigPath = defaultEditorConfig.getPath();
51+
}
52+
}
4653
if (editorConfigPath != null) {
4754
configPath = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(editorConfigPath)));
4855
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -50,9 +50,9 @@ void testKtlintEditorConfigOverride() throws Exception {
5050

5151
@Test
5252
void testReadCodeStyleFromEditorConfigFile() throws Exception {
53-
setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig");
53+
setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig");
5454
writePomWithKotlinSteps("<ktlint/>");
55-
checkKtlintOfficialStyle();
55+
checkIntellijIdeaStyle();
5656
}
5757

5858
@Test
@@ -87,4 +87,11 @@ private void checkKtlintOfficialStyle() throws Exception {
8787
mavenRunner().withArguments("spotless:apply").runNoError();
8888
assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
8989
}
90+
91+
private void checkIntellijIdeaStyle() throws Exception {
92+
String path = "src/main/kotlin/Main.kt";
93+
setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
94+
mavenRunner().withArguments("spotless:apply").runNoError();
95+
assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean");
96+
}
9097
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fun main() {
2+
val list = listOf(
3+
"hello",
4+
)
5+
}

0 commit comments

Comments
 (0)