Skip to content

OutdatedDocumentation - Check if only public property is documented #6057

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

Merged
merged 2 commits into from
May 5, 2023

Conversation

atulgpt
Copy link
Contributor

@atulgpt atulgpt commented Apr 29, 2023

Fixes #5217

@codecov
Copy link

codecov bot commented Apr 29, 2023

Codecov Report

Merging #6057 (2837cb2) into main (1b943d6) will increase coverage by 0.00%.
The diff coverage is 85.71%.

@@            Coverage Diff            @@
##               main    #6057   +/-   ##
=========================================
  Coverage     84.85%   84.85%           
- Complexity     3949     3979   +30     
=========================================
  Files           561      564    +3     
  Lines         13256    13312   +56     
  Branches       2315     2330   +15     
=========================================
+ Hits          11248    11296   +48     
- Misses          868      870    +2     
- Partials       1140     1146    +6     
Impacted Files Coverage Δ
...etekt/rules/documentation/OutdatedDocumentation.kt 91.30% <85.71%> (-2.45%) ⬇️

... and 8 files with indirect coverage changes

) {
val doc = element.docComment ?: return
val docDeclarations = getDocDeclarations(doc)
if (docDeclarations.isNotEmpty()) {
val elementDeclarations = elementDeclarationsProvider()
if (!declarationsMatch(docDeclarations, elementDeclarations)) {
val isInternalPrimaryConstructor = element is KtClass && isInternalOrPrivate(element.primaryConstructor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call this method reportIfDocumentationIsOutdated with 3 different element types. However, in this method we check whether element has 1 specific type (e.g. KtClass). For me, this feels like a polymorphism code smell. See here for more details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want me to move this check to visitClass method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just type KtClass of the 3 cases needs all those added checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code

private fun declarationsMatch(
doc: List<Declaration>,
element: List<Declaration>,
shouldAllowOnlyPropertyDoc: Boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using boolean parameters is at least controversial. One obvious reason is that it makes code harder to read and maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed boolean

Comment on lines 158 to 165
/**
* Exception thrown from MyLibrary that can not be created outside of the library.
* @property errorCode Description of param
*/
class MyLibraryException internal constructor(
val errorCode: String,
cause: Throwable?,
) : Exception(cause)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think smaller test code snippets are sufficient here to understand what's being tested here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this somehow hampering the readability of the test code? I saw the other TCs which use MyClass but current TC is inspired by the issue #5217 also conveys why someone wants to document property in this manner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't shorter, more concise and less noisy to add code snippets like this?

/**
 * Doc
 * @property b desc
*/
class A internal constructor(val b: String)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH even the current TC was readable to me. But I have updated the cases. Thanks for reviewing it

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good now.

@BraisGabin BraisGabin merged commit 4619fba into detekt:main May 5, 2023
@BraisGabin BraisGabin added this to the 1.23.0 milestone May 5, 2023
@atulgpt atulgpt deleted the fixes/5217 branch May 5, 2023 07:40
@cortinico cortinico changed the title Check if only public property is documented OutdatedDocumentation - Check if only public property is documented May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OutdatedDocumentation false positive with non-public constructor params
4 participants