Skip to content

Commit 07f2572

Browse files
Improve the messaging for "DataClassDefaultValues"
1 parent 2fadfbb commit 07f2572

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/kotlin/com/github/ivy/explicit/rule/DataClassDefaultValuesRule.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DataClassDefaultValuesRule(config: Config) : Rule(config) {
1111
id = "DataClassDefaultValues",
1212
severity = Severity.Maintainability,
1313
description = "Data class properties should not have default values. " +
14-
"Default values lead to implicit instance constructions and problems.",
14+
"Default values lead to implicit creation of instances which leads to problems.",
1515
debt = Debt.TWENTY_MINS,
1616
)
1717

@@ -33,8 +33,10 @@ class DataClassDefaultValuesRule(config: Config) : Rule(config) {
3333
}
3434

3535
private fun failureMessage(klass: KtClass, parameter: KtParameter): String = buildString {
36-
append("Data class '${klass.name}' should not have default values for properties. ")
36+
val className = klass.name
37+
append("Data class '$className' should not have default values. ")
3738
append("Found default value for property '${Message.parameter(parameter)}'. ")
38-
append("This can lead to implicit instance constructions and problems.")
39+
append("This allows for instances of '$className' to be created without explicitly specifying all properties, ")
40+
append("potentially leading to unintended or inconsistent states.")
3941
}
4042
}

src/test/kotlin/com/github/ivy/explicit/rule/DataClassDefaultValuesRuleTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class DataClassDefaultValuesRuleTest(private val env: KotlinCoreEnviron
2222
findings shouldHaveSize 1
2323
val message = findings.first().message
2424
message shouldBe """
25-
Data class 'A' should not have default values for properties. Found default value for property 'x: Int = 42'. This can lead to implicit instance constructions and problems.
25+
Data class 'A' should not have default values. Found default value for property 'x: Int = 42'. This allows for instances of 'A' to be created without explicitly specifying all properties, potentially leading to unintended or inconsistent states.
2626
""".trimIndent()
2727
}
2828

0 commit comments

Comments
 (0)