Skip to content

Commit

Permalink
Always load the experimental ruleset jar so that experimental rules c…
Browse files Browse the repository at this point in the history
…an be run (but only when enabled in the '.editorconfig' or when the "--experimental" flag is used in the CLI)
  • Loading branch information
paul-dingemans committed Dec 14, 2022
1 parent a0f7c5c commit ff4bc98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -351,7 +354,7 @@ internal class KtlintCommandLine {
internal fun ruleProviders() =
rulesetJarPaths
.toFilesURIList()
.loadRuleProviders(experimental, debug, disabledRules)
.loadRuleProviders(debug)

private fun List<String>.toFilesURIList() =
map {
Expand Down
Expand Up @@ -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<URL>.loadRuleProviders(
loadExperimental: Boolean,
debug: Boolean,
disabledRules: String,
): Set<RuleProvider> =
internal fun List<URL>.loadRuleProviders(debug: Boolean): Set<RuleProvider> =
this
.plus(
// Ensure that always at least one element exists in this list so that the rule sets provided by the KtLint
Expand All @@ -27,14 +23,7 @@ internal fun List<URL>.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()

Expand Down Expand Up @@ -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")

0 comments on commit ff4bc98

Please sign in to comment.