forked from detekt/detekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Suppressor.kt
45 lines (40 loc) · 1.49 KB
/
Suppressor.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 {
/**
* Given a Finding it decides if it should be suppressed (`true`) or not (`false`)
*/
fun shouldSuppress(finding: Finding): Boolean
}
private fun buildSuppressors(rule: ConfigAware, bindingContext: BindingContext): List<Suppressor> {
return listOfNotNull(
annotationSuppressorFactory(rule, bindingContext),
functionSuppressorFactory(rule, 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
}
}
}