website/versioned_docs/version-1.23.8/rules/libraries.md
Rules in this rule set report issues related to libraries API exposure.
Note: The libraries rule set is not included in the detekt-cli or Gradle plugin.
To enable this rule set, add detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-libraries:$version"
to your Gradle dependencies or reference the detekt-rules-libraries-jar with the --plugins option
in the command line interface.
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: Public API challenges in Kotlin
Active by default: Yes - Since v1.16.0
Debt: 20min
ignorePackages (default: ['*.internal', '*.internal.*'])
ignores classes in the specified packages.
data class C(val a: String) // violation: public data class
internal data class C(val a: String)
Functions/properties exposed as public APIs of a library should have an explicit return type. Inferred return type can easily be changed by mistake which may lead to breaking changes.
See also: Kotlin 1.4 Explicit API
Active by default: Yes - Since v1.2.0
Requires Type Resolution
Debt: 5min
allowOmitUnit (default: false)
if functions with Unit return type should be allowed without return type declaration
// code from a library
val strs = listOf("foo, bar")
fun bar() = 5
class Parser {
fun parse() = ...
}
// code from a library
val strs: List<String> = listOf("foo, bar")
fun bar(): Int = 5
class Parser {
fun parse(): ParsingResult = ...
}
Library typealias and classes should be internal or private.
Active by default: Yes - Since v1.16.0
Debt: 5min
// code from a library
class A
// code from a library
internal class A