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

Fixed KdocComments and KdocFormatting #1892

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

DrAlexD
Copy link
Member

@DrAlexD DrAlexD commented Dec 22, 2023

What's done:

  • Made refactoring in KdocComments.
  • Added fix test for case when there is class description and some properties in class KDoc at the same time.
  • Fixed bug in KdocFormatting for case when @property and @constructor basic tags haven't empty line before them.
  • Modified fix test for case when there is class description before @property tag.
  • Added smoke test for class KDoc. Currently disabled due to Empty lines in class constructor before properties with comments #1889.

Closes #1884

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (8636247) 78.28% compared to head (bebee7d) 78.31%.

Files Patch % Lines
...diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt 95.12% 0 Missing and 2 partials ⚠️
...ktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1892      +/-   ##
============================================
+ Coverage     78.28%   78.31%   +0.03%     
+ Complexity     2471     2458      -13     
============================================
  Files           134      134              
  Lines          8712     8698      -14     
  Branches       2210     2199      -11     
============================================
- Hits           6820     6812       -8     
+ Misses          905      903       -2     
+ Partials        987      983       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

JUnit Tests (Windows, EnricoMi/publish-unit-test-result-action@v2)

  166 files  ±0    166 suites  ±0   7m 14s ⏱️ -38s
1 436 tests +3  1 417 ✅ +1  19 💤 +2  0 ❌ ±0 
2 816 runs  +3  2 797 ✅ +1  19 💤 +2  0 ❌ ±0 

Results for commit bebee7d. ± Comparison against base commit 8636247.

Copy link
Contributor

JUnit Tests (macOS, EnricoMi/publish-unit-test-result-action@v2)

  166 files  ±0    166 suites  ±0   4m 50s ⏱️ - 3m 16s
1 436 tests +3  1 396 ✅ +1  40 💤 +2  0 ❌ ±0 
2 816 runs  +3  2 776 ✅ +1  40 💤 +2  0 ❌ ±0 

Results for commit bebee7d. ± Comparison against base commit 8636247.

@DrAlexD DrAlexD self-assigned this Dec 22, 2023
@DrAlexD DrAlexD added the bug Something isn't working label Dec 22, 2023
@DrAlexD DrAlexD added this to the 2.1.0 milestone Dec 22, 2023
@@ -306,7 +263,8 @@ class KdocComments(configRules: List<RulesConfig>) : DiktatRule(

KDOC_NO_CONSTRUCTOR_PROPERTY.warnAndFix(configRules, emitWarn, isFixMode, warningText, node.startOffset, node) {
val classNode = node.parent { it.elementType == CLASS }!!
val newKdocText = if (isParamTagNeeded) "/**\n * @param $parameterName\n */" else "/**\n * @property $parameterName\n */"
val paramOrPropertyTagText = if (isParamTagNeeded) "@param" else "@property"
Copy link
Member

Choose a reason for hiding this comment

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

Kotlin parser definitely has all these enum constants like param and property inside already. Use them.

) {
val wrongTagText = if (isParamTagNeeded) "* @property $parameterName" else "* @param $parameterName"
val replaceText = if (isParamTagNeeded) "* @param $parameterName" else "* @property $parameterName"
val paramOrPropertySwitchText = if (isParamTagNeeded) "@property" to "@param" else "@param" to "@property"
Copy link
Member

Choose a reason for hiding this comment

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

I see this code in 3+ places: can you please rework it as common functions?

fun replace(isParamTagNeeded, parameterName) {
    val (wrongTag, replacementTag) = if(isParamTagNeeded) (property, param) else (param, property)
    val wrongTagText = ...
    val replaceText = ...
    changeTagInKdoc(kdocBeforeClass, wrongTagText, replaceText)
}

Copy link
Member

@akuleshov7 akuleshov7 left a comment

Choose a reason for hiding this comment

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

I do not understand how 90% of refactoring work, but basically there are a lot of tests, so I believe in you :)

* kdoc
* class
* comment
*
Copy link
Member

Choose a reason for hiding this comment

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

Can you please check our codestyle document. Do we mention this newline?

class A<K : Any, P: Any, G: Any> constructor(
//single-line comment
class A<K : Any, P : Any, G : Any> constructor(
// single-line comment
Copy link
Member

Choose a reason for hiding this comment

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

I thought that test was checking how this space is fixed

* @param K
* @property openName single-line comment
* @property openLastName
* block
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 it was moved to a newline with a some purpose? Isn't it a newline rule that split long lines?

@@ -5,7 +5,7 @@ class A constructor(
) {}

class A constructor(
//single-line comment
// single-line comment
Copy link
Member

Choose a reason for hiding this comment

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

why do we change a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KDOC_NEWLINES_BEFORE_BASIC_TAGS is not fixing a newline problem from the first run
3 participants