Skip to content

Commit

Permalink
Report UseDataClass findings on class name (#5352)
Browse files Browse the repository at this point in the history
Closes #5338
  • Loading branch information
arturbosch committed Sep 25, 2022
1 parent 121b0d8 commit bb0f6cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -102,7 +102,7 @@ class UseDataClass(config: Config = Config.empty) : Rule(config) {
report(
CodeSmell(
issue,
Entity.from(klass),
Entity.from(klass.nameIdentifier ?: klass),
"The class ${klass.nameAsSafeName} defines no " +
"functionality and only holds data. Consider converting it to a data class."
)
Expand Down
Expand Up @@ -153,11 +153,16 @@ class UseDataClassSpec(val env: KotlinCoreEnvironment) {
inner class `does report data class candidates` {

@Test
fun `does report a data class candidate`() {
fun `does report a data class candidate on the class name`() {
val code = """
class DataClassCandidate1(val i: Int)
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(1)

val findings = subject.compileAndLint(code)

assertThat(findings).hasSize(1)
assertThat(findings).hasStartSourceLocation(1, 7)
assertThat(findings).hasEndSourceLocation(1, 26)
}

@Test
Expand Down

0 comments on commit bb0f6cd

Please sign in to comment.