detekt / detekt

Static code analysis for Kotlin
https://detekt.dev
Apache License 2.0
6.07k stars 751 forks source link

False negative for enum constants in UndocumentedPublic* rule group #7218

Open TWiStErRob opened 3 weeks ago

TWiStErRob commented 3 weeks ago

Steps to Reproduce

public enum class PublicEnum {
    Foo,
    Bar,
}

Configuration:

detekt.allRules = true
// Does not contain relevant lines, just a few rules deactivated or fine tuned.
detekt.config.from(rootProject.file("config/detekt/detekt.yml"))
dependencies { detektPlugins(libs.detekt.rules.libraries) }

Observed Behavior

src\main\kotlin\com\example\PublicEnum.kt:21:15: PublicEnum is missing required documentation. [UndocumentedPublicClass]

Expected Behavior

Findings for each of the undocumented enum constants. They're public API as well, accessible as PublicEnum.Foo. If

public companion object {
    public val Foo: PublicClass = ...
}

needs to be documented (The property Foo is missing documentation. [UndocumentedPublicProperty]), so does these enum constants Foo and Bar as they're essentially "just syntactic a shorthand" for the same.

Context

I'm relying on detekt to ensure that all my public API surface is documented.

This repro might be a trivial case, but imagine an enum with 10-12 values, and no documentation.

Your Environment

atulgpt commented 3 weeks ago

Should we make this configurable? Given documenting enum can be cumbersome

TWiStErRob commented 3 weeks ago

Documentation alone is cumbersome :) if someone enables this rule, they probably want it?