From 31702d6acf12bc1a6cca449c8600f72ca17d1f9c Mon Sep 17 00:00:00 2001 From: "Vitaly V. Pinchuk" Date: Wed, 21 Sep 2022 14:23:21 +0300 Subject: [PATCH] Revert docs, exclude rule, mark deprecated with ~~ - Revert docs for 1.21.0 - Exclude ElseCaseInsteadOfExhaustiveWhen rule - Mark deprecated with Strikethrough font. --- config/detekt/detekt.yml | 2 ++ detekt-core/src/main/resources/default-detekt-config.yml | 2 ++ detekt-core/src/main/resources/deprecation.properties | 1 - .../arturbosch/detekt/generator/printer/RulePrinter.kt | 8 +++++++- detekt-generator/src/test/resources/RuleSet.md | 4 +++- .../detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhen.kt | 1 - .../arturbosch/detekt/rules/bugs/PotentialBugProvider.kt | 2 +- .../rules/bugs/ElseCaseInsteadOfExhaustiveWhenSpec.kt | 2 +- .../versioned_docs/version-1.21.0/rules/potential-bugs.md | 8 -------- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 5fa036661b38..5237f6c5f663 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -124,6 +124,8 @@ potential-bugs: active: true DoubleMutabilityForCollection: active: false + ElseCaseInsteadOfExhaustiveWhen: + active: true ExitOutsideMain: active: false HasPlatformType: diff --git a/detekt-core/src/main/resources/default-detekt-config.yml b/detekt-core/src/main/resources/default-detekt-config.yml index 1a4a3c8e6f4d..2651b6961446 100644 --- a/detekt-core/src/main/resources/default-detekt-config.yml +++ b/detekt-core/src/main/resources/default-detekt-config.yml @@ -419,6 +419,8 @@ potential-bugs: - 'java.util.HashSet' - 'java.util.LinkedHashMap' - 'java.util.HashMap' + ElseCaseInsteadOfExhaustiveWhen: + active: false EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: diff --git a/detekt-core/src/main/resources/deprecation.properties b/detekt-core/src/main/resources/deprecation.properties index ccee103932ff..806f7a37515c 100644 --- a/detekt-core/src/main/resources/deprecation.properties +++ b/detekt-core/src/main/resources/deprecation.properties @@ -1,7 +1,6 @@ complexity>LongParameterList>threshold=Use `functionThreshold` and `constructorThreshold` instead empty-blocks>EmptyFunctionBlock>ignoreOverriddenFunctions=Use `ignoreOverridden` instead potential-bugs>DuplicateCaseInWhenExpression=Rule deprecated as compiler performs this check by default -potential-bugs>ElseCaseInsteadOfExhaustiveWhen=Rule deprecated as compiler performs this check by default potential-bugs>IgnoredReturnValue>restrictToAnnotatedMethods=Use `restrictToConfig` instead potential-bugs>LateinitUsage>excludeAnnotatedProperties=Use `ignoreAnnotated` instead potential-bugs>MissingWhenCase=Rule deprecated as compiler performs this check by default diff --git a/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/printer/RulePrinter.kt b/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/printer/RulePrinter.kt index 9c171d7f8e03..a78e66256e8e 100644 --- a/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/printer/RulePrinter.kt +++ b/detekt-generator/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/printer/RulePrinter.kt @@ -3,6 +3,7 @@ package io.gitlab.arturbosch.detekt.generator.printer import io.github.detekt.utils.MarkdownContent import io.github.detekt.utils.bold import io.github.detekt.utils.codeBlock +import io.github.detekt.utils.crossOut import io.github.detekt.utils.h3 import io.github.detekt.utils.h4 import io.github.detekt.utils.markdown @@ -14,7 +15,12 @@ internal object RulePrinter : DocumentationPrinter { override fun print(item: Rule): String { return markdown { - h3 { item.name } + if (item.isDeprecated()) { + h3 { crossOut { item.name } } + paragraph { escapeHtml(item.deprecationMessage!!) } + } else { + h3 { item.name } + } if (item.description.isNotEmpty()) { paragraph { escapeHtml(item.description) } diff --git a/detekt-generator/src/test/resources/RuleSet.md b/detekt-generator/src/test/resources/RuleSet.md index eef6f0201dc2..60b39b40556d 100644 --- a/detekt-generator/src/test/resources/RuleSet.md +++ b/detekt-generator/src/test/resources/RuleSet.md @@ -76,7 +76,9 @@ fun stuff(): Unit {} fun stuff() {} ``` -### DuplicateCaseInWhenExpression +### ~~DuplicateCaseInWhenExpression~~ + +is deprecated Duplicated `case` statements in a `when` expression detected. diff --git a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhen.kt b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhen.kt index 79e9977a115d..c2bccfdfae8c 100644 --- a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhen.kt +++ b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhen.kt @@ -50,7 +50,6 @@ import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean * */ @RequiresTypeResolution -@Deprecated("Rule deprecated as compiler performs this check by default") class ElseCaseInsteadOfExhaustiveWhen(config: Config = Config.empty) : Rule(config) { override val issue: Issue = Issue( diff --git a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/PotentialBugProvider.kt b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/PotentialBugProvider.kt index 413de756ffd4..693d0bc3f996 100644 --- a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/PotentialBugProvider.kt +++ b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/PotentialBugProvider.kt @@ -21,7 +21,7 @@ class PotentialBugProvider : DefaultRuleSetProvider { DontDowncastCollectionTypes(config), DoubleMutabilityForCollection(config), @Suppress("DEPRECATION") DuplicateCaseInWhenExpression(config), - @Suppress("DEPRECATION") ElseCaseInsteadOfExhaustiveWhen(config), + ElseCaseInsteadOfExhaustiveWhen(config), EqualsAlwaysReturnsTrueOrFalse(config), EqualsWithHashCodeExist(config), ExitOutsideMain(config), diff --git a/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhenSpec.kt b/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhenSpec.kt index ab7765a5ccb5..d7e5f7bd44f9 100644 --- a/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhenSpec.kt +++ b/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/ElseCaseInsteadOfExhaustiveWhenSpec.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test @KotlinCoreEnvironmentTest class ElseCaseInsteadOfExhaustiveWhenSpec(private val env: KotlinCoreEnvironment) { - private val subject = @Suppress("DEPRECATION") ElseCaseInsteadOfExhaustiveWhen() + private val subject = ElseCaseInsteadOfExhaustiveWhen() @Nested inner class Enum { diff --git a/website/versioned_docs/version-1.21.0/rules/potential-bugs.md b/website/versioned_docs/version-1.21.0/rules/potential-bugs.md index f747240ce3eb..45ba3ed1874f 100644 --- a/website/versioned_docs/version-1.21.0/rules/potential-bugs.md +++ b/website/versioned_docs/version-1.21.0/rules/potential-bugs.md @@ -156,8 +156,6 @@ var myMap = mapOf("answer" to 42) ### DuplicateCaseInWhenExpression -**Deprecated**: The rule is deprecated as compiler performs this check by default. - Flags duplicate `case` statements in `when` expressions. If a `when` expression contains the same `case` statement multiple times they should be merged. Otherwise, it might be @@ -188,8 +186,6 @@ when (i) { ### ElseCaseInsteadOfExhaustiveWhen -**Deprecated**: The rule is deprecated as compiler performs this check by default. - This rule reports `when` expressions that contain an `else` case even though they have an exhaustive set of cases. This occurs when the subject of the `when` expression is either an enum class, sealed class or of type boolean. @@ -667,8 +663,6 @@ Reports when the package declaration is missing. ### MissingWhenCase -**Deprecated**: The rule is deprecated as compiler performs this check by default. - Turn on this rule to flag `when` expressions that do not check that all cases are covered when the subject is an enum or sealed class and the `when` expression is used as a statement. @@ -801,8 +795,6 @@ fun bar(a: Any?): String { ### RedundantElseInWhen -**Deprecated**: The rule is deprecated as compiler performs this check by default. - Turn on this rule to flag `when` expressions that contain a redundant `else` case. This occurs when it can be verified that all cases are already covered when checking cases on an enum or sealed class.