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

Fix tests after migration to ktlint 1.0 #1737

Closed
nulls opened this issue Sep 20, 2023 · 1 comment · Fixed by #1769
Closed

Fix tests after migration to ktlint 1.0 #1737

nulls opened this issue Sep 20, 2023 · 1 comment · Fixed by #1769
Assignees
Labels
tests Improve testing
Milestone

Comments

@nulls
Copy link
Member

nulls commented Sep 20, 2023

All tests marked as @Disabled("https://github.com/saveourtool/diktat/issues/1737")

Some of them can fail is due to multiply runs, another -- due to modification of AST tree (limitation of kotlin 1.9):

java.lang.IllegalArgumentException: Missing extension point: org.jetbrains.kotlin.com.intellij.treeCopyHandler in container {}
	at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.getExtensionPoint(ExtensionsAreaImpl.java:250) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.openapi.extensions.BaseExtensionPointName.getPointImpl(BaseExtensionPointName.java:28) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.java:39) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.encodeInformation(ChangeUtil.java:43) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.lambda$encodeInformation$0(ChangeUtil.java:39) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:481) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.encodeInformation(ChangeUtil.java:39) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.copyElement(ChangeUtil.java:95) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.ChangeUtil.copyElement(ChangeUtil.java:87) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement.copyElement(TreeElement.java:58) ~[kotlin-compiler-embeddable-1.9.10.jar:1.9.10-release-459]
	at com.saveourtool.diktat.ruleset.rules.chapter6.classes.StatelessClassesRule$handleClass$1.invoke(StatelessClassesRule.kt:56) ~[main/:?]
	at com.saveourtool.diktat.ruleset.rules.chapter6.classes.StatelessClassesRule$handleClass$1.invoke(StatelessClassesRule.kt:51) ~[main/:?]
	at com.saveourtool.diktat.ruleset.constants.Warnings.warnAndFix(Warnings.kt:273) ~[main/:?]

Possible solutions: pinterest/ktlint#2044

@nulls nulls self-assigned this Sep 20, 2023
@nulls nulls changed the title Fix test after migration to ktlint 1.0 Fix tests after migration to ktlint 1.0 Sep 20, 2023
@nulls nulls added the tests Improve testing label Sep 20, 2023
@nulls nulls added this to the 2.0.0 milestone Sep 20, 2023
@nulls nulls assigned DrAlexD and unassigned nulls Sep 20, 2023
This was referenced Sep 21, 2023
nulls added a commit that referenced this issue Sep 21, 2023
### What's done:
- add checking children to support case with comma before comment
- reused ASTFactory

It's part of #1737
nulls added a commit that referenced this issue Sep 21, 2023
### What's done:
- removed a removing of moved ASTNode
- reused ASTFactory

It's part of #1737
nulls added a commit that referenced this issue Sep 22, 2023
### What's done:
- creating BLOCK section in THEN section
- reused ASTFactory

It's part of #1737
@nulls
Copy link
Member Author

nulls commented Sep 22, 2023

Ignored tests:

DiktatSmokeTestBase

  • indentation rule - example 1
  • disable chapters
  • fix can cause long line
  • regression - should correctly handle tags with empty lines
  • smoke test #1
  • smoke test #2
  • smoke test #5
  • smoke test with gradle script plugin

IndentationRuleFixTest

  • indentation rule - example 1

KdocCommentsFixTest

  • check fix without class kdoc

KdocMethodsFixTest

  • @param tag should be added to existing KDoc
  • KdocMethods rule should reformat code (full example)
  • @throws tag should be added to existing KDoc

BracesRuleFixTest

  • should add braces to do-while loops with empty body
  • should add braces to if-else statements - 1

FileStructureRuleTest

  • check by #4 should trigger

LineLengthFixTest

  • shouldn't fix
  • should fix short long right value
  • should fix complex long binary expressions
  • fix long Dot Qualified Expression
  • should fix annotation
  • should fix long string template while some fix is already done
  • should fix long binary expression
  • should fix long right value
  • should fix long comment
  • should not fix long comment which located on the line length limit
  • should fix long function

LocalVariablesWarnTest

  • need to allow declaring vars outside of loops
  • local variables defined in outer scope and used in several scopes
  • local variables defined in outer scope and used only in nested scope
  • need to allow declaring vars outside collection methods
  • should check variables initialized with constructor with no parameters

NewlinesRuleWarnTest

  • long argument list should be split into several lines

IndentationRuleFixTest

  • indentation rule - example 1

SmartCastRuleWarnTest

  • smart cast in when bad

ExtensionFunctionsSameNameWarnTest

  • should trigger on classes in other files

RulesConfigValidationTest

  • should throw error on invalid configuration section

VariablesWithAssignmentsSearchTest

  • testing proper variables search with lambda

VariablesWithUsagesSearchTest

  • testing proper variables search in class with the property in the end
  • testing proper variables search in companion object
  • testing proper variables search in function with a class nested in a function
  • testing proper variables search in companion object with less priority then property

nulls added a commit that referenced this issue Sep 22, 2023
### What's done:
- added toDeterministic() for repeatable functions
- fixed isFixMode and canBeAutoCorrected

It's part of #1737
DrAlexD added a commit to DrAlexD/diktat that referenced this issue Sep 25, 2023
### What's done:
- Reworked `insertEmptyBlock()` function for adding empty braces blocks to conditions and `do-while` loop with empty bodies.
- Added check for braces block existence to avoid duplicate braces block.
- Added tests for conditions including tests for cases of `else if` and cases of empty `if` and `else` bodies.

It's part of saveourtool#1737
DrAlexD added a commit that referenced this issue Sep 25, 2023
### What's done:
- Reworked `insertEmptyBlock()` function for adding empty braces blocks to conditions and `do-while` loop with empty bodies.
- Added check for braces block existence to avoid duplicate braces blocks.
- Added tests for conditions including tests for cases of `else if` and cases of empty `if` and `else` bodies.

It's part of #1737
DrAlexD added a commit to DrAlexD/diktat that referenced this issue Sep 28, 2023
### What's done:
- Added non-fixed warning `KDOC_EXTRA_PROPERTY` for case when `private` or `override` property has `@property` tag in class-KDoc.
- Removed fixed warning `KDOC_NO_CONSTRUCTOR_PROPERTY` for case when `override` property  hasn't `@property` tag in class-KDoc.
- Added non-fixed warning `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` for case when `private` or `override` property has comment before.
- Changed warning `KDOC_NO_CONSTRUCTOR_PROPERTY` to `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` for case when non-`private` and non-`override` property has comment before.
- Added check is warning `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` fixable for case when non-`private` and non-`override` property has tags in KDoc-comment before. If it has = non-fixed.
- Fixed case when text from comment before non-`private` and non-`override` property didn't append to the end of `@property` text in class-KDoc for that property.
- Fixed case when `@property` text in class-KDoc didn't create for KDoc-comment before non-`private` and non-`override` property.
- Fixed functions `removeWithWhiteSpace` and `removeChildMergingSurroundingWhitespaces` for additional handling KDoc-comments.
- Reworked fix tests. Added fix test for case when `@property` tag exist in class-KDoc.
- Added warning tests.

It's part of saveourtool#1737
DrAlexD added a commit to DrAlexD/diktat that referenced this issue Oct 2, 2023
- Fixed multiple generation of `@param` and `@throws` tags.

It's part of saveourtool#1737
DrAlexD added a commit that referenced this issue Oct 3, 2023
- Fixed multiple generation of `@param` and `@throws` tags.

It's part of #1737
DrAlexD added a commit to DrAlexD/diktat that referenced this issue Oct 5, 2023
### What's done:
- Fixed bug when fix-result of rule `LineLength` execution still contained `LineLength` warnings. To fix this, added loop that trying to fix `LineLength` warnings until warnings run out.
- Added `unFix()` method realization inside `FunAndProperty` and `ValueArgumentList` classes to undo unnecessary fixes.
- Fixed bug for case when long comment followed multiline property initialization.
- Fixed and reworked several fix tests.

It's part of saveourtool#1737
DrAlexD added a commit to DrAlexD/diktat that referenced this issue Oct 5, 2023
### What's done:
- Fixed bug related to string templates starting with new line.

It's part of saveourtool#1737
DrAlexD added a commit that referenced this issue Oct 5, 2023
### What's done:
- Fixed bug related to string templates starting with new line.

It's part of #1737
DrAlexD added a commit that referenced this issue Oct 16, 2023
### What's done:
- Changed warning `KDOC_NO_CONSTRUCTOR_PROPERTY` to `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` in some cases when property or parameter has comment before.
- Added check is warning `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` fixable for case when property or parameter has any tags in KDoc-comment before. If it has = non-fixed.
- Added configuration for `@param` tags creation: `isParamTagsForParameters` and `isParamTagsForPrivateProperties`.
- Added fixed warnings `KDOC_NO_CONSTRUCTOR_PROPERTY` and `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` for cases when configuration options are on, and then `private` properties and parameters must have `@param` tags in class-KDoc. Additionally added logic for replacing incorrect tag with correct one regardless of whether configuration is enabled or not.
- Added non-fixed warning `KDOC_EXTRA_PROPERTY` for redundant `@param` tags in class-KDoc.
- Reworked fix tests. Added tests for cases when `@property` or `@param` tag exist in class-KDoc.
- Added new warning tests.

It's part of #1737
DrAlexD added a commit that referenced this issue Oct 16, 2023
### What's done:
- Fixed bug when fix-result of rule `LineLength` execution still contained `LineLength` warnings. To fix this, added loop that trying to fix `LineLength` rule warnings until warnings run out.
- Added `MAX_FIX_NUMBER` for limit on fixing to avoid infinite loop. If the limit is reached, then error message is displayed.
- Added `unFix()` method realization inside `FunAndProperty` and `ValueArgumentList` classes to undo incorrect unnecessary fixes.
- Fixed bug for case when long comment followed multiline property initialization.
- Fixed and reworked several fix tests.

It's part of #1737
nulls added a commit that referenced this issue Oct 26, 2023
### What's done:
- fixed rule PACKAGE_NAME_MISSING

It closes #1737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Improve testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants