File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed
main/java/com/diffplug/spotless/maven/kotlin
test/java/com/diffplug/spotless/maven/kotlin
testlib/src/main/resources/kotlin/ktlint Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2023 DiffPlug
2
+ * Copyright 2016-2024 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package com .diffplug .spotless .maven .kotlin ;
17
17
18
+ import java .io .File ;
18
19
import java .util .Collections ;
19
20
import java .util .HashMap ;
20
21
import java .util .List ;
@@ -43,6 +44,12 @@ public class Ktlint implements FormatterStepFactory {
43
44
public FormatterStep newFormatterStep (final FormatterStepConfig stepConfig ) {
44
45
String ktlintVersion = version != null ? version : KtLintStep .defaultVersion ();
45
46
FileSignature configPath = null ;
47
+ if (editorConfigPath == null ) {
48
+ File defaultEditorConfig = new File (".editorconfig" );
49
+ if (defaultEditorConfig .exists ()) {
50
+ editorConfigPath = defaultEditorConfig .getPath ();
51
+ }
52
+ }
46
53
if (editorConfigPath != null ) {
47
54
configPath = ThrowingEx .get (() -> FileSignature .signAsList (stepConfig .getFileLocator ().locateFile (editorConfigPath )));
48
55
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2023 DiffPlug
2
+ * Copyright 2016-2024 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,9 +50,9 @@ void testKtlintEditorConfigOverride() throws Exception {
50
50
51
51
@ Test
52
52
void testReadCodeStyleFromEditorConfigFile () throws Exception {
53
- setFile (".editorconfig" ).toResource ("kotlin/ktlint/ktlint_official /.editorconfig" );
53
+ setFile (".editorconfig" ).toResource ("kotlin/ktlint/intellij_idea /.editorconfig" );
54
54
writePomWithKotlinSteps ("<ktlint/>" );
55
- checkKtlintOfficialStyle ();
55
+ checkIntellijIdeaStyle ();
56
56
}
57
57
58
58
@ Test
@@ -87,4 +87,11 @@ private void checkKtlintOfficialStyle() throws Exception {
87
87
mavenRunner ().withArguments ("spotless:apply" ).runNoError ();
88
88
assertFile (path ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean" );
89
89
}
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
+ }
90
97
}
Original file line number Diff line number Diff line change
1
+ fun main() {
2
+ val list = listOf(
3
+ "hello",
4
+ )
5
+ }
You can’t perform that action at this time.
0 commit comments