KT.FORBIDDEN_PUBLIC_DATA_CLASS

Data class in public APIs

Data classes are bad for binary compatibility in public APIs. Avoid using them. This rule is aimed at library maintainers. If you are developing a final application you can ignore this issue. More info: https://jakewharton.com/public-api-challenges-in-kotlin/

Noncompliant Code

Copy
data class C(val a: String) // violation: public data class

Compliant Code

Copy
internal data class C(val a: String)

Options

  • excludes (default: ['**'])

    path filter

  • ignorePackages (default: ['*.internal', '*.internal.*'])

    ignores classes in the specified packages

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