Improve issue description and smell message of DestructuringDeclarationWithTooManyEntries (#4795)

This commit is contained in:
Brais Gabín
2022-05-12 13:00:11 +02:00
committed by GitHub
parent a51adb8df5
commit 5af71841d7

View File

@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
* data class TooManyElements(val a: Int, val b: Int, val c: Int, val d: Int)
* val (a, b, c, d) = TooManyElements(1, 2, 3, 4)
* </noncompliant>
*
* <compliant>
* data class FewerElements(val a: Int, val b: Int, val c: Int)
* val (a, b, c) = TooManyElements(1, 2, 3)
@@ -29,8 +30,7 @@ class DestructuringDeclarationWithTooManyEntries(config: Config = Config.empty)
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"The destructuring declaration contains too many entries, making it difficult to read. Consider refactoring " +
"to avoid using a destructuring declaration for this case.",
"Too many entries in a destructuring declaration make the code hard to understand.",
Debt.TEN_MINS
)
@@ -39,7 +39,9 @@ class DestructuringDeclarationWithTooManyEntries(config: Config = Config.empty)
override fun visitDestructuringDeclaration(destructuringDeclaration: KtDestructuringDeclaration) {
if (destructuringDeclaration.entries.size > maxDestructuringEntries) {
report(CodeSmell(issue, Entity.from(destructuringDeclaration), issue.description))
val message = "The destructuring declaration contains ${destructuringDeclaration.entries.size} but only " +
"$maxDestructuringEntries are allowed."
report(CodeSmell(issue, Entity.from(destructuringDeclaration), message))
}
super.visitDestructuringDeclaration(destructuringDeclaration)
}