Fix KDocReferencesNonPublicProperty false positive#5534
Merged
picklebento merged 1 commit intodetekt:mainfrom Dec 12, 2022
dzirbel:kdocProperty
Merged
Fix KDocReferencesNonPublicProperty false positive#5534picklebento merged 1 commit intodetekt:mainfrom dzirbel:kdocProperty
picklebento merged 1 commit intodetekt:mainfrom
dzirbel:kdocProperty
Conversation
KDocReferencesNonPublicProperty has a common false-positive where there is a name overlap with a public and non-public property (e.g. a local variable). This should not be reported as an issue since the kdoc is referencing the public field. To fix this, we need to add awareness of the public properties and filter out name overlaps when checking if non-public properties are being referenced in the kdoc. This also includes properties declared as constructor parameters. Also add a test that constructor parameters are allowed to be referenced in the class kdoc even when they are private fields.
Contributor
Author
|
An alternative I'm only realizing now is to try to just process the class-level properties and skip local variables entirely (if this is possible). That sounds cleaner but would slightly weaken the rule since it would not warn for references to local variables - but that seems like more of an edge case that the rule probably wasn't intended to cover in the first place. |
picklebento
approved these changes
Dec 12, 2022
|
|
||
| val comment = klass.docComment?.text ?: return | ||
|
|
||
| klass.primaryConstructor?.accept( |
Member
There was a problem hiding this comment.
Do you know why we couldn't use klass.primaryConstructor?.valueParameters?
Member
There was a problem hiding this comment.
Agreed that this PR is improving by fixing known edge cases. This can be done as a follow-up (Today I learned that [param] syntax does not work if param is only a parameter not property.)
picklebento
approved these changes
Dec 12, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KDocReferencesNonPublicProperty has a common false-positive where there is a name overlap with a public and non-public property (e.g. a local variable). This should not be reported as an issue since the kdoc is referencing the public field.
To fix this, we need to add awareness of the public properties and filter out name overlaps when checking if non-public properties are being referenced in the kdoc. This also includes properties declared as constructor parameters.
Also add a test that constructor parameters are allowed to be referenced in the class kdoc even when they are private fields.