Skip to content

Commit

Permalink
Delete MultiRule (detekt#6288)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico authored and mgroth0 committed Feb 11, 2024
1 parent 297a24d commit 6a37666
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 304 deletions.
11 changes: 0 additions & 11 deletions detekt-api/api/detekt-api.api
Expand Up @@ -412,17 +412,6 @@ public final class io/gitlab/arturbosch/detekt/api/MetricKt {
public static final field DEFAULT_FLOAT_CONVERSION_FACTOR I
}

public abstract class io/gitlab/arturbosch/detekt/api/MultiRule : io/gitlab/arturbosch/detekt/api/BaseRule {
public fun <init> ()V
public final fun getActiveRules ()Ljava/util/Set;
public abstract fun getRules ()Ljava/util/List;
protected fun postVisit (Lorg/jetbrains/kotlin/psi/KtFile;)V
protected fun preVisit (Lorg/jetbrains/kotlin/psi/KtFile;)V
public final fun runIfActive (Lio/gitlab/arturbosch/detekt/api/Rule;Lkotlin/jvm/functions/Function1;)V
public final fun setActiveRules (Ljava/util/Set;)V
public fun visitCondition (Lorg/jetbrains/kotlin/psi/KtFile;)Z
}

public abstract interface class io/gitlab/arturbosch/detekt/api/Notification {
public abstract fun getLevel ()Lio/gitlab/arturbosch/detekt/api/Notification$Level;
public abstract fun getMessage ()Ljava/lang/String;
Expand Down
Expand Up @@ -10,10 +10,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
*
* Custom rule implementations should actually use [Rule] as base class.
*
* The extraction of this class from [Rule] actually resulted from the need
* of running many different checks on the same KtFile but within a single
* potential costly visiting process, see [MultiRule].
*
* This base rule class abstracts over single and multi rules and allows the
* detekt core engine to only care about a single type.
*/
Expand Down

This file was deleted.

Expand Up @@ -102,7 +102,6 @@ internal class Analyzer(
@Suppress("DEPRECATION")
fun isCorrectable(rule: BaseRule): Boolean = when (rule) {
is Rule -> rule.autoCorrect
is io.gitlab.arturbosch.detekt.api.MultiRule -> rule.rules.any { it.autoCorrect }
else -> error("No other rule type expected.")
}

Expand Down
Expand Up @@ -5,7 +5,6 @@ import io.github.detekt.tooling.api.spec.RulesSpec
import io.gitlab.arturbosch.detekt.api.BaseRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.RuleId
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetId
Expand Down Expand Up @@ -33,13 +32,7 @@ fun RuleSet.visitFile(
}

fun associateRuleIdsToRuleSetIds(ruleSets: Sequence<RuleSet>): Map<RuleId, RuleSetId> {
fun extractIds(rule: BaseRule) =
@Suppress("DEPRECATION")
if (rule is io.gitlab.arturbosch.detekt.api.MultiRule) {
rule.rules.asSequence().map(Rule::ruleId)
} else {
sequenceOf(rule.ruleId)
}
fun extractIds(rule: BaseRule) = sequenceOf(rule.ruleId)
return ruleSets.flatMap { ruleSet ->
ruleSet.rules
.asSequence()
Expand Down
Expand Up @@ -3,7 +3,6 @@ package io.gitlab.arturbosch.detekt.core.suppressors
import io.gitlab.arturbosch.detekt.api.BaseRule
import io.gitlab.arturbosch.detekt.api.ConfigAware
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.Rule
import org.jetbrains.kotlin.resolve.BindingContext

fun interface Suppressor {
Expand All @@ -21,25 +20,8 @@ private fun buildSuppressors(rule: ConfigAware, bindingContext: BindingContext):
}

internal fun getSuppressors(rule: BaseRule, bindingContext: BindingContext): List<Suppressor> {
@Suppress("DEPRECATION")
return when (rule) {
is io.gitlab.arturbosch.detekt.api.MultiRule -> rule.rules.flatMap { innerRule ->
buildSuppressors(innerRule, bindingContext).map { suppressor -> InnerSuppressor(innerRule, suppressor) }
}
is ConfigAware -> buildSuppressors(rule, bindingContext)
else -> emptyList()
}
}

private class InnerSuppressor(
private val rule: Rule,
private val suppressor: Suppressor
) : Suppressor {
override fun shouldSuppress(finding: Finding): Boolean {
return if (finding.id == rule.issue.id) {
suppressor.shouldSuppress(finding)
} else {
false
}
}
}
Expand Up @@ -24,11 +24,8 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
import org.jetbrains.kotlin.resolve.BindingContext
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

class SuppressionSpec {

Expand Down Expand Up @@ -278,30 +275,6 @@ class SuppressionSpec {
fun `suppresses by combination of detekt prefix, rule set and rule id`() {
assertCodeIsSuppressed("""@Suppress("detekt:complexity:LongParameterList")$code""", config)
}
@Nested
inner class MultiRule {
@Suppress("DEPRECATION")
private lateinit var subject: io.gitlab.arturbosch.detekt.api.MultiRule
@BeforeEach
fun setupSubject() {
subject = AMultiRule(config)
}
@ParameterizedTest
@ValueSource(
strings = [
"complexity",
"LongParameterList",
"detekt.complexity.LongParameterList"
]
)
fun `is suppressed by rule id`(ruleId: String) {
assertThat(subject.lint("""@Suppress("$ruleId")$code""")).isEmpty()
}
}
}
}
Expand All @@ -320,12 +293,6 @@ private fun isSuppressedBy(annotation: String, argument: String): Boolean {
return annotatedClass.isSuppressedBy("Test", setOf("alias"))
}
private class AMultiRule(config: Config) :
@Suppress("DEPRECATION")
io.gitlab.arturbosch.detekt.api.MultiRule() {
override val rules: List<Rule> = listOf(TestLPL(config))
}
private class TestRule(config: Config = Config.empty) : Rule(config) {
override val issue = Issue("Test", Severity.CodeSmell, "", Debt.TWENTY_MINS)
var expected: String? = "Test"
Expand Down

This file was deleted.

Expand Up @@ -11,7 +11,6 @@ import io.gitlab.arturbosch.detekt.api.Severity
import io.gitlab.arturbosch.detekt.test.TestConfig
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.resolve.BindingContext
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

class SuppressorsSpec {
Expand Down Expand Up @@ -55,33 +54,6 @@ class SuppressorsSpec {

assertThat(suppress).isTrue()
}

@Nested
inner class MultiRule {
@Test
fun `A finding that should be suppressed`() {
val rule = AMultiRule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(noIgnorableCodeSmell) }

assertThat(suppress).isFalse()
}

@Test
fun `A finding that should not be suppressed`() {
val rule = AMultiRule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(ignorableCodeSmell) }

assertThat(suppress).isTrue()
}
}
}

private class AMultiRule(config: Config) :
@Suppress("DEPRECATION")
io.gitlab.arturbosch.detekt.api.MultiRule() {
override val rules: List<Rule> = listOf(ARule(config))
}

private class ARule(config: Config = Config.empty) : Rule(config) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6a37666

Please sign in to comment.