Skip to content

Commit

Permalink
Data class rule: removing several cases from the scope of the inspection
Browse files Browse the repository at this point in the history
### What's done:
- review notes
  • Loading branch information
orchestr7 committed Jul 25, 2022
1 parent a90cf2d commit 5205bad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ class DataClassesRule(configRules: List<RulesConfig>) : 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<ASTNode>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand Down

0 comments on commit 5205bad

Please sign in to comment.