Skip to content

Commit

Permalink
Warn about enabled rules that are not going to run
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Aug 16, 2022
1 parent 69a9b90 commit da7a73d
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -8,6 +8,7 @@ import io.gitlab.arturbosch.detekt.api.FileProcessListener
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.MultiRule
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetId
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.api.internal.CompilerResources
Expand Down Expand Up @@ -47,6 +48,9 @@ internal class Analyzer(
@Suppress("DEPRECATION")
val dataFlowValueFactory = DataFlowValueFactoryImpl(languageVersionSettings)
val compilerResources = CompilerResources(languageVersionSettings, dataFlowValueFactory)
if (bindingContext == BindingContext.EMPTY) {
warnAboutEnabledRequiresTypeResolutionRules(settings::info)
}
val findingsPerFile: FindingsResult =
if (settings.spec.executionSpec.parallelAnalysis) {
runAsync(ktFiles, bindingContext, compilerResources)
Expand Down Expand Up @@ -187,3 +191,16 @@ internal fun ProcessingSpec.workaroundConfiguration(config: Config): Config = wi

return declaredConfig ?: getDefaultConfiguration()
}

private fun warnAboutEnabledRequiresTypeResolutionRules(log: (String) -> Unit) {
providers.asSequence()
.map { it to config.subConfig(it.ruleSetId) }
.filter { (_, ruleSetConfig) -> ruleSetConfig.isActive() }
.map { (provider, ruleSetConfig) -> provider.instance(ruleSetConfig) to ruleSetConfig }
.flatMap { (ruleSet, _) -> ruleSet.rules.asSequence() }
.filter { rule -> (rule as? Rule)?.active == true }
.filter { rule -> rule::class.hasAnnotation<RequiresTypeResolution>() }
.forEach { rule ->
log("The rule '${rule.ruleId}' requires type resolution but it was run without it.")
}
}

0 comments on commit da7a73d

Please sign in to comment.