/
RuleSet.kt
45 lines (38 loc) · 1.41 KB
/
RuleSet.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.api
import io.gitlab.arturbosch.detekt.api.internal.PathFilters
import io.gitlab.arturbosch.detekt.api.internal.absolutePath
import io.gitlab.arturbosch.detekt.api.internal.validateIdentifier
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
import java.nio.file.Paths
typealias RuleSetId = String
/**
* A rule set is a collection of rules and must be defined within a rule set provider implementation.
*/
class RuleSet(val id: RuleSetId, val rules: List<BaseRule>) {
init {
validateIdentifier(id)
}
/**
* Is used to determine if a given [KtFile] should be analyzed at all.
*/
@Deprecated("Exposes detekt-core implementation details.")
var pathFilters: PathFilters? = null
/**
* Visits given file with all rules of this rule set, returning a list
* of all code smell findings.
*/
@Deprecated("Exposes detekt-core implementation details.")
fun accept(file: KtFile, bindingContext: BindingContext = BindingContext.EMPTY): List<Finding> =
if (isFileIgnored(file)) {
emptyList()
} else {
rules.flatMap {
it.visitFile(file, bindingContext)
it.findings
}
}
@Suppress("DEPRECATION")
private fun isFileIgnored(file: KtFile) =
pathFilters?.isIgnored(Paths.get(file.absolutePath())) == true
}