/
Spec.kt
86 lines (74 loc) · 2.99 KB
/
Spec.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package io.gitlab.arturbosch.detekt.cli
import io.github.detekt.tooling.api.spec.ProcessingSpec
import io.github.detekt.tooling.api.spec.RulesSpec
import io.gitlab.arturbosch.detekt.api.commaSeparatedPattern
internal fun CliArgs.createSpec(output: Appendable, error: Appendable): ProcessingSpec {
val args = this
return ProcessingSpec {
logging {
debug = args.debug
outputChannel = output
errorChannel = error
}
project {
basePath = args.basePath
inputPaths = args.inputPaths
excludes = asPatterns(args.excludes)
includes = asPatterns(args.includes)
}
rules {
autoCorrect = args.autoCorrect
@Suppress("DEPRECATION")
activateAllRules = args.failFast || args.allRules
maxIssuePolicy = when (val count = args.maxIssues) {
null -> RulesSpec.MaxIssuePolicy.NonSpecified // prefer to read from config
0 -> RulesSpec.MaxIssuePolicy.NoneAllowed
in -1 downTo Int.MIN_VALUE -> RulesSpec.MaxIssuePolicy.AllowAny
else -> RulesSpec.MaxIssuePolicy.AllowAmount(count)
}
excludeCorrectable = false // not yet supported; loaded from config
runPolicy = args.toRunPolicy()
}
baseline {
path = args.baseline
shouldCreateDuringAnalysis = args.createBaseline
}
config {
useDefaultConfig = args.buildUponDefaultConfig
shouldValidateBeforeAnalysis = null
knownPatterns = emptyList()
// ^^ cli does not have these properties yet; specified in yaml config for now
configPaths = config?.let { MultipleExistingPathConverter().convert(it) }.orEmpty()
resources = configResource?.let { MultipleClasspathResourceConverter().convert(it) }.orEmpty()
}
execution {
parallelParsing = args.parallel
parallelAnalysis = args.parallel
}
extensions {
disableDefaultRuleSets = args.disableDefaultRuleSets
fromPaths { args.plugins?.let { MultipleExistingPathConverter().convert(it) }.orEmpty() }
}
reports {
args.reportPaths.forEach {
report { it.kind to it.path }
}
}
compiler {
jvmTarget = args.jvmTarget
languageVersion = args.languageVersion?.versionString
classpath = args.classpath?.trim()
jdkHome = args.jdkHome
}
}
}
private fun asPatterns(rawValue: String?): List<String> =
rawValue?.trim()
?.commaSeparatedPattern(",", ";")
?.toList()
.orEmpty()
private fun CliArgs.toRunPolicy(): RulesSpec.RunPolicy {
val parts = runRule?.split(":") ?: return RulesSpec.RunPolicy.NoRestrictions
require(parts.size == 2) { "Pattern 'RuleSetId:RuleId' expected." }
return RulesSpec.RunPolicy.RestrictToSingleRule(parts[0] to parts[1])
}