From 5205bad9bf39d06b2f04bc3b8be66bb4bd699447 Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Mon, 25 Jul 2022 13:57:24 +0300 Subject: [PATCH] Data class rule: removing several cases from the scope of the inspection ### What's done: - review notes --- .../rules/chapter6/classes/DataClassesRule.kt | 6 +++--- .../ruleset/chapter6/DataClassesRuleWarnTest.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt index 3db21c24ec..02cd7b3af4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt @@ -125,16 +125,16 @@ class DataClassesRule(configRules: List) : DiktatRule( } /** - * We do not exclude inner classes and enums here as if they have no + * We do not exclude inner classes here as if they have no * methods, then we definitely can refactor the code and make them data classes. - * We only exclude: value/inline classes, annotations, interfaces, abstract classes, + * We only exclude: value/inline classes, enums, annotations, interfaces, abstract classes, * sealed classes and data classes itself. For sure there will be other corner cases, * for example, simple classes in Spring marked with @Entity annotation. * For these classes we expect users to Suppress warning manually for each corner case. **/ private fun KtClass.isDefinitelyNotDataClass() = isValue() || isAnnotation() || isInterface() || isData() || - isSealed() || isInline() || isAbstract() + isSealed() || isInline() || isAbstract() || isEnum() @Suppress("UnsafeCallOnNullableType") private fun areGoodAccessors(accessors: List): Boolean { diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt index 2f24bac51d..35db05ab75 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt @@ -239,6 +239,20 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { ) } + @Test + @Tag(USE_DATA_CLASS) + fun `should not trigger on enums`() { + lintMethod( + """ + |enum class Style(val str: String) { + | PASCAL_CASE("PascalCase"), + | SNAKE_CASE("UPPER_SNAKE_CASE"), + | ; + |} + """.trimMargin() + ) + } + @Test @Tag(USE_DATA_CLASS) fun `should trigger on class with parameter in constructor`() {