KT.DESTRUCTURING_DECLARATION_WITH_TOO_MANY_ENTRIES

Destructuring declaration with too many entries

Destructuring declarations with too many entries are hard to read and understand. To increase readability they should be refactored to reduce the number of entries or avoid using a destructuring declaration.

Noncompliant Code

Copy
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)

Compliant Code

Copy
data class FewerElements(val a: Int, val b: Int, val c: Int)
val (a, b, c) = TooManyElements(1, 2, 3)

Options

  • maxDestructuringEntries (default: 3)

    maximum allowed elements in a destructuring declaration

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html