From ff4bc982aa278b50762a5d388e033595f47a7fc7 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Wed, 14 Dec 2022 18:19:24 +0100 Subject: [PATCH] Always load the experimental ruleset jar so that experimental rules can be run (but only when enabled in the '.editorconfig' or when the "--experimental" flag is used in the CLI) --- .../ktlint/internal/KtlintCommandLine.kt | 7 +++++-- .../ktlint/internal/LoadRuleProviders.kt | 18 ++---------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt index 4e1742a813..b6a3c6b9bb 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt @@ -18,6 +18,7 @@ import com.pinterest.ktlint.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.core.api.editorconfig.CodeStyleValue import com.pinterest.ktlint.core.api.editorconfig.RuleExecution import com.pinterest.ktlint.core.api.editorconfig.createRuleExecutionEditorConfigProperty +import com.pinterest.ktlint.core.api.editorconfig.createRuleSetExecutionEditorConfigProperty import com.pinterest.ktlint.core.api.loadBaseline import com.pinterest.ktlint.core.api.relativeRoute import com.pinterest.ktlint.core.initKtLintKLogger @@ -254,7 +255,9 @@ internal class KtlintCommandLine { get() = EditorConfigOverride .EMPTY_EDITOR_CONFIG_OVERRIDE - .applyIf(disabledRules.isNotBlank()) { + .applyIf(experimental) { + plus(createRuleSetExecutionEditorConfigProperty("experimental:all") to RuleExecution.enabled) + }.applyIf(disabledRules.isNotBlank()) { plus(*disabledRulesEditorConfigOverrides()) }.applyIf(android) { plus(CODE_STYLE_PROPERTY to CodeStyleValue.android) @@ -351,7 +354,7 @@ internal class KtlintCommandLine { internal fun ruleProviders() = rulesetJarPaths .toFilesURIList() - .loadRuleProviders(experimental, debug, disabledRules) + .loadRuleProviders(debug) private fun List.toFilesURIList() = map { diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt index 1da317fee4..58c824582b 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt @@ -14,11 +14,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() /** * Loads given list of paths to jar files. For files containing a [RuleSetProviderV2] class, get all [RuleProvider]s. */ -internal fun List.loadRuleProviders( - loadExperimental: Boolean, - debug: Boolean, - disabledRules: String, -): Set = +internal fun List.loadRuleProviders(debug: Boolean): Set = this .plus( // Ensure that always at least one element exists in this list so that the rule sets provided by the KtLint @@ -27,14 +23,7 @@ internal fun List.loadRuleProviders( ) // Remove JAR files which were provided multiple times .distinct() - .map { getRuleProvidersFromJar(it, debug) } - .flatMap { rulesProvidersFromJar -> - // Remove disabled rule sets - rulesProvidersFromJar - .filterKeys { loadExperimental || it != "experimental" } - .filterKeys { !(disabledRules.isStandardRuleSetDisabled() && it == "standard") } - .values - } + .flatMap { getRuleProvidersFromJar(it, debug).values } .flatten() .toSet() @@ -74,7 +63,4 @@ private fun getRuleProvidersFromJar( } } -private fun String.isStandardRuleSetDisabled() = - this.split(",").map { it.trim() }.toSet().contains("standard") - private val KTLINT_RULE_SETS = listOf("standard", "experimental")