forked from detekt/detekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeprecatedPrinter.kt
47 lines (42 loc) · 2.13 KB
/
DeprecatedPrinter.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
package io.gitlab.arturbosch.detekt.generator.printer
import io.gitlab.arturbosch.detekt.generator.collection.Configuration
import io.gitlab.arturbosch.detekt.generator.collection.Rule
import io.gitlab.arturbosch.detekt.generator.collection.RuleSetPage
object DeprecatedPrinter : DocumentationPrinter<List<RuleSetPage>> {
@Suppress("NestedBlockDepth")
override fun print(item: List<RuleSetPage>): String {
val builder = StringBuilder()
item.forEach { ruleSet ->
ruleSet.rules.forEach { rule ->
if (rule.isDeprecated()) {
builder.appendLine(writeRule(ruleSet, rule))
}
rule.configuration.forEach { configuration ->
if (configuration.isDeprecated()) {
builder.appendLine(writeProperty(ruleSet, rule, configuration))
}
}
}
}
builder.appendLine(writeMigratedRules())
return builder.toString()
}
}
private fun writeRule(ruleSet: RuleSetPage, rule: Rule): String {
@Suppress("UnsafeCallOnNullableType")
return "${ruleSet.ruleSet.name}>${rule.name}=${rule.deprecationMessage!!}"
}
private fun writeProperty(ruleSet: RuleSetPage, rule: Rule, configuration: Configuration): String {
@Suppress("UnsafeCallOnNullableType")
return "${ruleSet.ruleSet.name}>${rule.name}>${configuration.name}=${configuration.deprecated!!}"
}
internal fun writeMigratedRules(): String {
return """
formatting>TrailingComma=Rule is split between `TrailingCommaOnCallSite` and `TrailingCommaOnDeclarationSite` now.
style>ForbiddenPublicDataClass=Rule migrated to `libraries` ruleset plugin
style>LibraryCodeMustSpecifyReturnType=Rule migrated to `libraries` ruleset plugin
style>LibraryEntitiesShouldNotBePublic=Rule migrated to `libraries` ruleset plugin
style>MandatoryBracesIfStatements=Use `BracesOnIfStatements` with `always` configuration instead
complexity>ComplexMethod=Rule is renamed to `CyclomaticComplexMethod` to distinguish between Cyclomatic Complexity and Cognitive Complexity
""".trimIndent()
}