KT.DATA_CLASS_CONTAINS_FUNCTIONS

Function inside data class have not been marked as a conversion function

This rule reports functions inside data classes which have not been marked as a conversion function. Data classes should mainly be used to store data. This rule assumes that they should not contain any extra functions aside functions that help with converting objects from/to one another. Data classes will automatically have a generated equals, toString and hashCode function by the compiler.

Noncompliant Code

Copy
data class DataClassWithFunctions(val i: Int) {
    fun foo() { }
}

Options

  • conversionFunctionPrefix (default: to)

    allowed conversion function names

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