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

UndocumentedPublicClass false positive for inner types #2580

Closed
jcornaz opened this issue Apr 5, 2020 · 3 comments · Fixed by #2588
Closed

UndocumentedPublicClass false positive for inner types #2580

jcornaz opened this issue Apr 5, 2020 · 3 comments · Fixed by #2588

Comments

@jcornaz
Copy link

jcornaz commented Apr 5, 2020

Expected Behavior

Given the following source code:

private class MyClass {
  object MyInnerObject
}

I don't expect the UndocumentedPublicClass to be reported because MyClass is private.

Yes MyInnerObject is not explicitly marked private. But being an inner type of a private one, makes MyInnerObject effectively private.

Observed Behavior

Given the snippet above and the rule UndocumentedPublicClass activated:

  UndocumentedPublicClass:
    active: true
    searchInInnerObject: true

A UndocumentedPublicClass issue is reported, saying that MyInnerObject is public and undocumented.

Steps to Reproduce

The snippets above should be enough to reproduce the issue.

Context

I added a private class with inner types and got the mentioned false-positive reported by detekt.

Your Environment

  • Version of detekt used: 1.7.4
  • Version of Gradle used: 6.3
  • Operating System and version: Linux 5.5.13
@BraisGabin
Copy link
Member

I think that we don't even need searchInInnerObject that object should never be flagged.

@schalkms
Copy link
Member

schalkms commented Apr 7, 2020

Thanks for reporting this.
The rule doesn't take nested classes into account at the moment.
Following code should be flagged, however, since the nested and outer class(es) are public.

class Outer(val i: Int) {
    // must be documented
    class Nested(val s: String) {
    }
}

@jcornaz
Copy link
Author

jcornaz commented Apr 7, 2020

@schalkms

The rule doesn't take nested classes into account at the moment.

Mmmh. Yes they do... There is even explicit config for it.

The documentation says:

By default this rule also searches for nested and inner classes and objects. This default behavior can be changed with the configuration options of this rule.

And, yes your example should and is flagged. As far as I can see, that works as expected.

The problem is only when the outer class is not public.

arturbosch pushed a commit that referenced this issue Apr 11, 2020
* Fix false positives in UndocumentedPublicProperty

Properties in classes that are nested, public and undocumented are not flagged by this rule anymore.

Related #2580

* Fix detekt warning

* Remove unnecessary test
arturbosch pushed a commit that referenced this issue Apr 11, 2020
* Fix false positive in UndocumentedPublicClass

Classes that are nested, non-public and undocumented are not flagged by this rule anymore.

Closes #2580

* Fix detekt issue
@arturbosch arturbosch added this to the 1.8.0 milestone Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants