mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Improve issue description and smell message of DestructuringDeclarationWithTooManyEntries (#4795)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user