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

[UndocumentedPublicProperty] Allow inline comments for properties in primary constructor as documentation #3722

Merged

Conversation

arhont375
Copy link
Contributor

@arhont375 arhont375 commented Apr 30, 2021

Fixes #3677

Allow inline comments for properties in primary constructor as a property documentation.

Changes:

  1. Introduce new configuration parameter for UndocumentedPublicProperty that defaults to false to keep current behavior by default <-- decided that configuration is not needed
  2. Slightly change filtering rules
  3. Add tests

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

BraisGabin
BraisGabin previously approved these changes Apr 30, 2021
@codecov
Copy link

codecov bot commented Apr 30, 2021

Codecov Report

Merging #3722 (c34e031) into main (57ffa78) will increase coverage by 0.65%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3722      +/-   ##
============================================
+ Coverage     78.04%   78.70%   +0.65%     
- Complexity     2883     2892       +9     
============================================
  Files           473      473              
  Lines          9302     9310       +8     
  Branches       1767     1705      -62     
============================================
+ Hits           7260     7327      +67     
- Misses         1078     1080       +2     
+ Partials        964      903      -61     
Impacted Files Coverage Δ Complexity Δ
.../rules/documentation/UndocumentedPublicProperty.kt 88.46% <100.00%> (+8.46%) 28.00 <0.00> (+4.00)
...arturbosch/detekt/rules/style/UnnecessaryFilter.kt 78.78% <0.00%> (-1.22%) 14.00% <0.00%> (ø%)
...kotlin/io/gitlab/arturbosch/detekt/DetektPlugin.kt 5.88% <0.00%> (-0.37%) 0.00% <0.00%> (ø%)
...urbosch/detekt/generator/collection/Annotations.kt 71.42% <0.00%> (ø) 0.00% <0.00%> (ø%)
.../main/kotlin/io/github/detekt/parser/KtCompiler.kt 77.27% <0.00%> (+0.80%) 8.00% <0.00%> (+3.00%)
...n/io/github/detekt/report/html/HtmlOutputReport.kt 95.77% <0.00%> (+1.40%) 21.00% <0.00%> (ø%)
...ekt/generator/printer/rulesetpage/ConfigPrinter.kt 79.16% <0.00%> (+2.08%) 9.00% <0.00%> (ø%)
...itlab/arturbosch/detekt/api/internal/Signatures.kt 76.59% <0.00%> (+2.12%) 0.00% <0.00%> (ø%)
...n/io/github/detekt/metrics/processors/util/LLOC.kt 75.55% <0.00%> (+2.22%) 3.00% <0.00%> (ø%)
...h/detekt/rules/naming/MemberNameEqualsClassName.kt 81.08% <0.00%> (+2.70%) 13.00% <0.00%> (ø%)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57ffa78...c34e031. Read the comment docs.

@@ -22,6 +22,9 @@ import org.jetbrains.kotlin.psi.psiUtil.isPublic
* This also includes public properties defined in a primary constructor.
* If the codebase should have documentation on all public properties enable this rule to enforce this.
* Overridden properties are excluded by this rule.
*
* @configuration allowInlineConstructorPropertyComments - allow properties defined in a primary constructor to have
* inline documentation (default: `false`).
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this configuration. This rule checks if a public property is undocumented. This configuration is about if we like the kdoc there or not. I see the point of it but it's out of the scope of this rule. The property is correctly documented so this rule should not complain about where it was documented.

It we want to discorage that usage we could create another rule but I think that we should keep the focust of this rule.

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 see your point here to follow the name of the rule precisely, but I feel that this configuration is necessary to keep current behavior of Detekt.
There already maybe projects that rely on current behavior and change of this rule would be unexpected by them.

Also maybe the decision about what the correct way of documentation should be on users?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that we should allow this to be configured. It is completely valid to document the property inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, let me reconfirm to be sure.

@BraisGabin agreed with the fact that inline documentation is valid and this PR is OK, just need to remove configuration option?
I will update PR after your confirmation

Copy link
Member

Choose a reason for hiding this comment

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

Correct

@BraisGabin BraisGabin dismissed their stale review April 30, 2021 13:09

I changed my opinion about it.

!it.isPublicNotOverridden() || !it.hasValOrVar() -> false
isInlineConstructorPropertyCommentsAllowed && it.docComment != null -> false
else -> it.isUndocumented(comment)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH this is really hard to understand. Maybe it would be better to do something along the lines of

constructor.valueParameters
    .filter { it.isPublicNotOverridden() }
    .filter { it.hasValOrVar() }
    .filter { it.isUndocumented(comment) }
    .filter { it.docComment == null }
    .forEach { report(it) }

@BraisGabin BraisGabin merged commit e41de94 into detekt:main May 8, 2021
@BraisGabin
Copy link
Member

Thanks for the contribution 👍

@cortinico cortinico added this to the 1.17.0 milestone May 12, 2021
@cortinico cortinico changed the title Allow inline comments for properties in primary constructor as documentation [UndocumentedPublicProperty] Allow inline comments for properties in primary constructor as documentation May 12, 2021
chao2zhang pushed a commit to chao2zhang/detekt that referenced this pull request May 13, 2021
…ntation (detekt#3722)

* Allow inline comments for properties in primary constructor
Fixes detekt#3677

* Revert blank line removal in UndocumentedPublicProperty

* - remove configuration
- update tests

* - remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UndocumentedPublicProperty doesn't recognize inline documentation in the primary constructor.
4 participants