Skip to content

Commit

Permalink
Improve the messaging for "DataClassFunctions"
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jan 30, 2024
1 parent 07f2572 commit a514f20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class DataClassFunctionsRule(config: Config) : Rule(config) {
override val issue = Issue(
id = "DataClassFunctions",
severity = Severity.Maintainability,
description = "Data classes should not define behavior. " +
"Their purpose is to model data.",
description = "Data classes should not be tied to any behavior. " +
"Their responsibility is to solely model data.",
debt = Debt.TWENTY_MINS,
)

Expand Down Expand Up @@ -42,7 +42,7 @@ class DataClassFunctionsRule(config: Config) : Rule(config) {
function: KtNamedFunction
): String = buildString {
append("Data class '${klass.name}' should not contain functions. ")
append("Data classes should only model data and not define behavior. ")
append("Found: function '${Message.functionSignature(function)}'.")
append("Found: function '${Message.functionSignature(function)}'. ")
append("Data classes should only model data and should not be tied to any behavior.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DataClassFunctionsRuleTest(private val env: KotlinCoreEnvironment
@Test
fun `reports data class having one function`() {
val code = """
data class A(
data class Abc(
val x: Int
) {
fun a() = 42
Expand All @@ -24,7 +24,7 @@ internal class DataClassFunctionsRuleTest(private val env: KotlinCoreEnvironment
findings shouldHaveSize 1
val message = findings.first().message
message shouldBe """
Data class 'A' should not contain functions. Data classes should only model data and not define behavior. Found: function 'a()'.
Data class 'Abc' should not contain functions. Found: function 'a()'. Data classes should only model data and should not be tied to any behavior.
""".trimIndent()
}

Expand Down

0 comments on commit a514f20

Please sign in to comment.