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 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.
1515 */
1616package com .diffplug .spotless .maven .kotlin ;
1717
18+ import java .io .File ;
1819import java .util .Collections ;
1920import java .util .HashMap ;
2021import 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 }
Original file line number Diff line number Diff line change 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}
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