|
15 | 15 | */
|
16 | 16 | package com.diffplug.gradle.spotless;
|
17 | 17 |
|
| 18 | +import java.io.File; |
18 | 19 | import java.io.IOException;
|
19 | 20 | import java.util.Collections;
|
20 | 21 | import java.util.Map;
|
@@ -43,12 +44,17 @@ public KotlinGradleExtension(SpotlessExtension spotless) {
|
43 | 44 | }
|
44 | 45 |
|
45 | 46 | /** Adds the specified version of <a href="https://github.com/pinterest/ktlint">ktlint</a>. */
|
46 |
| - public KotlinFormatExtension ktlint(String version) { |
| 47 | + public KotlinFormatExtension ktlint(String version) throws IOException { |
47 | 48 | Objects.requireNonNull(version, "version");
|
48 |
| - return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); |
| 49 | + FileSignature editorConfigPath = null; |
| 50 | + File defaultEditorConfig = getProject().getRootProject().file(".editorConfig"); |
| 51 | + if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { |
| 52 | + editorConfigPath = FileSignature.signAsList(defaultEditorConfig); |
| 53 | + } |
| 54 | + return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); |
49 | 55 | }
|
50 | 56 |
|
51 |
| - public KotlinFormatExtension ktlint() { |
| 57 | + public KotlinFormatExtension ktlint() throws IOException { |
52 | 58 | return ktlint(KtLintStep.defaultVersion());
|
53 | 59 | }
|
54 | 60 |
|
@@ -104,7 +110,7 @@ public KotlinFormatExtension editorConfigOverride(Map<String, Object> editorConf
|
104 | 110 | }
|
105 | 111 |
|
106 | 112 | private FormatterStep createStep() {
|
107 |
| - return KtLintStep.createForScript(version, provisioner(), useExperimental, userData, editorConfigOverride); |
| 113 | + return KtLintStep.createForScript(version, provisioner(), useExperimental, editorConfigPath, userData, editorConfigOverride); |
108 | 114 | }
|
109 | 115 | }
|
110 | 116 |
|
|
0 commit comments