Skip to content

OutdatedDocumentation - Check if only public property is documented - #6057

Merged
BraisGabin merged 2 commits into
detekt:mainfrom
atulgpt:fixes/5217
May 5, 2023
Merged

BraisGabin merged 2 commits into
detekt:mainfrom
atulgpt:fixes/5217

Conversation

@atulgpt

@atulgpt atulgpt commented Apr 29, 2023

Copy link
Copy Markdown
Contributor

Fixes #5217

@codecov

codecov Bot commented Apr 29, 2023 •

Copy link
Copy Markdown

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

if (docDeclarations.isNotEmpty()) {
val elementDeclarations = elementDeclarationsProvider()
if (!declarationsMatch(docDeclarations, elementDeclarations)) {
val isInternalPrimaryConstructor = element is KtClass && isInternalOrPrivate(element.primaryConstructor)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@schalkms schalkms left a comment

Copy link
Copy Markdown
Member

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

This branch was successfully deployed

1 active deployment
Preview — 2837cb2b Deployed Apr 30, 2023 by vercel[bot]
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