diff --git a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt index 47b3bf2d3c44..44cc294f5bde 100644 --- a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt +++ b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt @@ -52,6 +52,9 @@ internal class Analyzer( } else { runSync(ktFiles, bindingContext, compilerResources) } + if (bindingContext == BindingContext.EMPTY) { + warnAboutEnabledRequiresTypeResolutionRules(settings::info) + } val findingsPerRuleSet = HashMap>() for (findings in findingsPerFile) { @@ -140,6 +143,19 @@ internal class Analyzer( return result } + + 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() } + .forEach { rule -> + log("The rule '${rule.ruleId}' requires type resolution but it was run without it.") + } + } } private fun filterSuppressedFindings(rule: BaseRule, bindingContext: BindingContext): List { diff --git a/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/AnalyzerSpec.kt b/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/AnalyzerSpec.kt index 5ed0993ef36c..952149dfcca5 100644 --- a/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/AnalyzerSpec.kt +++ b/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/AnalyzerSpec.kt @@ -74,7 +74,9 @@ class AnalyzerSpec(val env: KotlinCoreEnvironment) { val analyzer = Analyzer(settings, listOf(StyleRuleSetProvider()), emptyList()) assertThat(settings.use { analyzer.run(listOf(compileForTest(testFile))) }.values.flatten()).isEmpty() - assertThat(output.toString()).isEmpty() + assertThat(output.toString()).isEqualTo( + "The rule 'RequiresTypeResolutionMaxLineLength' requires type resolution but it was run without it.\n" + ) } @Test @@ -89,7 +91,9 @@ class AnalyzerSpec(val env: KotlinCoreEnvironment) { val analyzer = Analyzer(settings, listOf(StyleRuleSetProvider(30)), emptyList()) assertThat(settings.use { analyzer.run(listOf(compileForTest(testFile))) }.values.flatten()).hasSize(1) - assertThat(output.toString()).isEmpty() + assertThat(output.toString()).isEqualTo( + "The rule 'RequiresTypeResolutionMaxLineLength' requires type resolution but it was run without it.\n" + ) } @Test