Skip to content

Commit

Permalink
Do not recreate id mapping for each file - #2341
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Mar 2, 2020
1 parent 250a499 commit 7ffd971
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -8,7 +8,8 @@ import io.gitlab.arturbosch.detekt.api.MultiRule
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.RuleSetId
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.core.rules.associateRuleIdToRuleSetId
import io.gitlab.arturbosch.detekt.core.rules.IdMapping
import io.gitlab.arturbosch.detekt.core.rules.associateRuleIdsToRuleSetIds
import io.gitlab.arturbosch.detekt.core.rules.createRuleSet
import io.gitlab.arturbosch.detekt.core.rules.isActive
import io.gitlab.arturbosch.detekt.core.rules.shouldAnalyzeFile
Expand All @@ -22,6 +23,8 @@ class Detektor(
) {

private val config: Config = settings.config
private val idMapping: IdMapping =
associateRuleIdsToRuleSetIds(providers.associate { it.ruleSetId to it.instance(config).rules })

fun run(
ktFiles: Collection<KtFile>,
Expand Down Expand Up @@ -86,7 +89,6 @@ class Detektor(
else -> error("No other rule type expected.")
}

val idMapping = associateRuleIdToRuleSetId(ruleSets)
val (correctableRules, otherRules) =
ruleSets.asSequence()
.flatMap { (_, value) -> value.asSequence() }
Expand Down
Expand Up @@ -51,7 +51,7 @@ fun RuleSet.visitFile(
typealias IdMapping = Map<RuleId, RuleSetId>

@Suppress("RemoveExplicitTypeArguments") // FIXME 1.4: type inference bug
fun associateRuleIdToRuleSetId(rules: Map<RuleSetId, List<BaseRule>>): IdMapping {
fun associateRuleIdsToRuleSetIds(rules: Map<RuleSetId, List<BaseRule>>): IdMapping {
fun extractIds(rule: BaseRule) =
if (rule is MultiRule) rule.rules.map(Rule::ruleId) else listOf(rule.ruleId)
return rules.entries
Expand Down

0 comments on commit 7ffd971

Please sign in to comment.