Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UtilityClassWithPublicConstructor should not be reported for sealed classes #2005

Closed
svick opened this issue Oct 9, 2019 · 0 comments · Fixed by #2016
Closed

UtilityClassWithPublicConstructor should not be reported for sealed classes #2005

svick opened this issue Oct 9, 2019 · 0 comments · Fixed by #2016
Milestone

Comments

@svick
Copy link

svick commented Oct 9, 2019

Observed Behavior

I have a sealed class with no members of its own, except for a factory function:

sealed class Parent {
    companion object {
        fun create(foo: Int?, bar: String?): Parent? =
            when {
                foo != null -> FooChild(foo)
                bar != null -> BarChild(bar)
                else -> null
            }
    }
}

data class FooChild(val foo: Int) : Parent()

data class BarChild(val bar: String) : Parent()

This reports:

UtilityClassWithPublicConstructor - [Parent]

Expected Behavior

UtilityClassWithPublicConstructor should not be reported for Parent, or any other sealed class, since sealed classes don't have public constructors.

Your Environment

  • Version of detekt used: 1.1.0
@arturbosch arturbosch added this to the 1.2.0 milestone Oct 12, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants