Skip to content

Commit

Permalink
Improve issue description and smell message of DestructuringDeclarati…
Browse files Browse the repository at this point in the history
…onWithTooManyEntries (#4795)
  • Loading branch information
BraisGabin committed May 12, 2022
1 parent a51adb8 commit 5af7184
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -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)
Expand All @@ -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
)

Expand All @@ -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)
}
Expand Down

0 comments on commit 5af7184

Please sign in to comment.