KT.DATA_CLASS_SHOULD_BE_IMMUTABLE

Mutable properties inside data class

This rule reports mutable properties inside data classes. Data classes should mainly be used to store immutable data. This rule assumes that they should not contain any mutable properties.

Noncompliant Code

Copy
data class MutableDataClass(var i: Int) {
    var s: String? = null
}

Compliant Code

Copy
data class ImmutableDataClass(
    val i: Int,
    val s: String?
)

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