From cf6c76f83003c290dbbaaadf4d83dba14550e158 Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Tue, 28 May 2024 10:46:36 +1000 Subject: [PATCH 1/7] Check if ktlint_code_style is set in .editorconfig before overriding it ktlint_code_style gets unconditionally overridden to its default value (intellij_idea) when the editorConfigOverride map is non-empty but does not define it. As a result, it gets overridden even if it's actually defined in the .editorconfig file. This change checks if ktlint_code_style is already defined in .editorconfig before overriding it to its default value. Fixes https://github.com/diffplug/spotless/issues/2142. --- .../compat/KtLintCompat1Dot0Dot0Adapter.java | 23 +++++++++++-------- .../gradle/spotless/KotlinExtensionTest.java | 21 ++++++++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 1790f9475c..a6e631718d 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -93,20 +93,21 @@ public String format( .flatMap(loader -> loader.get().getRuleProviders().stream()) .collect(Collectors.toUnmodifiableSet()); - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); - } else { - editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( - RuleProvider::createNewRuleInstance).collect(Collectors.toList()), - editorConfigOverrideMap); - } EditorConfigDefaults editorConfig; if (editorConfigPath == null || !Files.exists(editorConfigPath)) { editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); } else { editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); } + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); + } else { + editorConfigOverride = createEditorConfigOverride( + editorConfig, + allRuleProviders.stream().map(RuleProvider::createNewRuleInstance).collect(Collectors.toList()), + editorConfigOverrideMap); + } return new KtLintRuleEngine( allRuleProviders, @@ -120,7 +121,7 @@ public String format( /** * Create EditorConfigOverride from user provided parameters. */ - private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + private static EditorConfigOverride createEditorConfigOverride(final EditorConfigDefaults editorConfig, final List rules, Map editorConfigOverrideMap) { // Get properties from rules in the rule sets Stream> ruleProperties = rules.stream() .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); @@ -132,7 +133,9 @@ private static EditorConfigOverride createEditorConfigOverride(final List .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); // The default style had been changed from intellij_idea to ktlint_official in version 1.0.0 - if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) { + boolean isCodeStyleDefinedInEditorConfig = editorConfig.getValue().getSections().stream() + .anyMatch(section -> section.getProperties().containsKey("ktlint_code_style")); + if (!isCodeStyleDefinedInEditorConfig && !editorConfigOverrideMap.containsKey("ktlint_code_style")) { editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 1e96d34574..9720276e15 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,6 +127,25 @@ void testReadCodeStyleFromEditorConfigFile() throws IOException { checkKtlintOfficialStyle(); } + @Test + void testEditorConfigOverrideWithUnsetCodeStyleDoesNotOverrideEditorConfigCodeStyleWithDefault() throws IOException { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().editorConfigOverride([", + " ktlint_test_key: true,", + " ])", + " }", + "}"); + checkKtlintOfficialStyle(); + } + @Test void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); From 0be12f5aab17b6bd56609da019896c36c5c1d9ea Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Wed, 29 May 2024 22:34:36 +1000 Subject: [PATCH 2/7] 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. --- .../com/diffplug/spotless/maven/kotlin/Ktlint.java | 9 ++++++++- .../diffplug/spotless/maven/kotlin/KtlintTest.java | 13 ++++++++++--- ...erimentalEditorConfigOverride.intellijIdea.clean | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 2459a52828..f90ed25089 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.maven.kotlin; +import java.io.File; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -43,6 +44,12 @@ public class Ktlint implements FormatterStepFactory { public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); FileSignature configPath = null; + if (editorConfigPath == null) { + File defaultEditorConfig = new File(".editorconfig"); + if (defaultEditorConfig.exists()) { + editorConfigPath = defaultEditorConfig.getPath(); + } + } if (editorConfigPath != null) { configPath = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(editorConfigPath))); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index fe5b0e1b57..aa03aeae76 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,9 +50,9 @@ void testKtlintEditorConfigOverride() throws Exception { @Test void testReadCodeStyleFromEditorConfigFile() throws Exception { - setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); writePomWithKotlinSteps(""); - checkKtlintOfficialStyle(); + checkIntellijIdeaStyle(); } @Test @@ -87,4 +87,11 @@ private void checkKtlintOfficialStyle() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); } + + private void checkIntellijIdeaStyle() throws Exception { + 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.intellijIdea.clean"); + } } diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean new file mode 100644 index 0000000000..532177d038 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean @@ -0,0 +1,5 @@ +fun main() { + val list = listOf( + "hello", + ) +} From ccf141e05fb46bab8046bf8b898e6ffd3161d2b2 Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Wed, 29 May 2024 22:49:29 +1000 Subject: [PATCH 3/7] Add ktlint test to plugin-maven This verifies that the previous fix which checks if ktlint_code_style is already defined in .editorconfig before overriding it works as expected in plugin-maven. --- .../diffplug/spotless/maven/kotlin/KtlintTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index aa03aeae76..0ad716dd35 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -55,6 +55,17 @@ void testReadCodeStyleFromEditorConfigFile() throws Exception { checkIntellijIdeaStyle(); } + @Test + void testEditorConfigOverrideWithUnsetCodeStyleDoesNotOverrideEditorConfigCodeStyleWithDefault() throws Exception { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + writePomWithKotlinSteps("\n" + + " \n" + + " true\n" + + " \n" + + ""); + checkKtlintOfficialStyle(); + } + @Test void testSetEditorConfigCanOverrideEditorConfigFile() throws Exception { setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); From 145321473f4d85c1aa7fa69cc4165ea9b92753bb Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Wed, 29 May 2024 22:55:59 +1000 Subject: [PATCH 4/7] Update CHANGES.md files --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dbeb53a0a2..e7b4594edc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945)) * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) ### Fixed +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) * Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bccb62dcb1..a55f78385d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) * Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082)) ### Fixed +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) * Full no-asterisk support for configuration cache ([#2088](https://github.com/diffplug/spotless/pull/2088) closes [#1274](https://github.com/diffplug/spotless/issues/1274) and [#987](https://github.com/diffplug/spotless/issues/987)). * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 557e011ac4..3d9da8349f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) * Skip execution in M2E (incremental) builds by default ([#1814](https://github.com/diffplug/spotless/issues/1814), [#2037](https://github.com/diffplug/spotless/issues/2037)) ### Fixed +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) +* Default EditorConfig path to ".editorconfig" [#2143] * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) * Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096)) From 2effcbda9f0bb8e5d2cd6fcc60740f5f44b1aa62 Mon Sep 17 00:00:00 2001 From: OlivierGenez Date: Fri, 31 May 2024 23:11:47 +1000 Subject: [PATCH 5/7] Fix CHANGES.md files links Co-authored-by: Zongle Wang --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e7b4594edc..c0d6abde75 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,7 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945)) * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) ### Fixed -* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2143](https://github.com/diffplug/spotless/issues/2143)) * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) * Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a55f78385d..e8d0461798 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,7 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) * Add support for formatting and sorting Maven POMs ([#2082](https://github.com/diffplug/spotless/issues/2082)) ### Fixed -* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2143](https://github.com/diffplug/spotless/issues/2143)) * Full no-asterisk support for configuration cache ([#2088](https://github.com/diffplug/spotless/pull/2088) closes [#1274](https://github.com/diffplug/spotless/issues/1274) and [#987](https://github.com/diffplug/spotless/issues/987)). * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3d9da8349f..1308c36768 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,8 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031)) * Skip execution in M2E (incremental) builds by default ([#1814](https://github.com/diffplug/spotless/issues/1814), [#2037](https://github.com/diffplug/spotless/issues/2037)) ### Fixed -* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2142]) -* Default EditorConfig path to ".editorconfig" [#2143] +* Check if ktlint_code_style is set in .editorconfig before overriding it ([#2143](https://github.com/diffplug/spotless/issues/2143)) +* Default EditorConfig path to ".editorconfig" ([#2143](https://github.com/diffplug/spotless/issues/2143)) * Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990)) * Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052)) * Made ShadowCopy (`npmInstallCache`) more robust by re-creating the cache dir if it goes missing ([#1984](https://github.com/diffplug/spotless/issues/1984),[2096](https://github.com/diffplug/spotless/pull/2096)) From f33f8bebcf46c4f9518a7cfa1989e0b051ec4211 Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Sat, 1 Jun 2024 11:29:33 +1000 Subject: [PATCH 6/7] Revert unneeded changes to KtlintTest --- .../diffplug/spotless/maven/kotlin/KtlintTest.java | 11 ++--------- ...xperimentalEditorConfigOverride.intellijIdea.clean | 5 ----- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 0ad716dd35..5586335449 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -50,9 +50,9 @@ void testKtlintEditorConfigOverride() throws Exception { @Test void testReadCodeStyleFromEditorConfigFile() throws Exception { - setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); writePomWithKotlinSteps(""); - checkIntellijIdeaStyle(); + checkKtlintOfficialStyle(); } @Test @@ -98,11 +98,4 @@ private void checkKtlintOfficialStyle() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); } - - private void checkIntellijIdeaStyle() throws Exception { - 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.intellijIdea.clean"); - } } diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean deleted file mode 100644 index 532177d038..0000000000 --- a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.intellijIdea.clean +++ /dev/null @@ -1,5 +0,0 @@ -fun main() { - val list = listOf( - "hello", - ) -} From 397a7fd51313670216fcccaa9cebc64837f416ec Mon Sep 17 00:00:00 2001 From: Olivier Genez Date: Mon, 3 Jun 2024 13:03:51 +1000 Subject: [PATCH 7/7] Apply minor Ktlint implementation refactor --- .../java/com/diffplug/spotless/maven/kotlin/Ktlint.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index f90ed25089..a54e0d9764 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -31,6 +31,8 @@ import com.diffplug.spotless.maven.FormatterStepFactory; public class Ktlint implements FormatterStepFactory { + private static final File defaultEditorConfig = new File(".editorconfig"); + @Parameter private String version; @Parameter @@ -44,11 +46,8 @@ public class Ktlint implements FormatterStepFactory { public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); FileSignature configPath = null; - if (editorConfigPath == null) { - File defaultEditorConfig = new File(".editorconfig"); - if (defaultEditorConfig.exists()) { - editorConfigPath = defaultEditorConfig.getPath(); - } + if (editorConfigPath == null && defaultEditorConfig.exists()) { + editorConfigPath = defaultEditorConfig.getPath(); } if (editorConfigPath != null) { configPath = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(editorConfigPath)));