From 6eb72632ce058c4486c67f84dc065af22b7a5809 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 21 Sep 2023 15:48:19 +0300 Subject: [PATCH] Fixed CommentsFormatting for else blocks ### What's done: - removed a removing of moved ASTNode - reused ASTFactory It's part of #1737 --- .../ruleset/rules/chapter2/kdoc/CommentsFormatting.kt | 7 +++---- .../diktat/ruleset/chapter2/CommentsFormattingFixTest.kt | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt index ac8ac8f985..a2748d24aa 100644 --- a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt +++ b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.KtNodeTypes.IF import org.jetbrains.kotlin.KtNodeTypes.PROPERTY import org.jetbrains.kotlin.KtNodeTypes.THEN import org.jetbrains.kotlin.KtNodeTypes.VALUE_ARGUMENT_LIST +import org.jetbrains.kotlin.com.intellij.lang.ASTFactory import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl @@ -154,13 +155,11 @@ class CommentsFormatting(configRules: List) : DiktatRule( val elseCodeBlock = elseBlock.getFirstChildWithType(BLOCK)!! elseCodeBlock.addChild(comment, elseCodeBlock.firstChildNode.treeNext) - elseCodeBlock.addChild(PsiWhiteSpaceImpl("\n"), + elseCodeBlock.addChild(ASTFactory.whitespace("\n"), elseCodeBlock.firstChildNode.treeNext) - node.removeChild(comment) } else { elseKeyWord.treeParent.addChild(comment, elseKeyWord.treeNext) - elseKeyWord.treeParent.addChild(PsiWhiteSpaceImpl("\n"), elseKeyWord.treeNext) - node.removeChild(comment) + elseKeyWord.treeParent.addChild(ASTFactory.whitespace("\n"), elseKeyWord.treeNext) } val whiteSpace = elseKeyWord.prevNodeUntilNode(THEN, WHITE_SPACE) diff --git a/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt b/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt index 7df69e2ebb..c299d74135 100644 --- a/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt +++ b/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt @@ -32,7 +32,6 @@ class CommentsFormattingFixTest : FixTestBase("test/paragraph2/kdoc/", ::Comment Tag(IF_ELSE_COMMENTS), Tag(FIRST_COMMENT_NO_BLANK_LINE) ) - @Disabled("https://github.com/saveourtool/diktat/issues/1737") fun `check lines and spaces in comments`() { fixAndCompare("KdocCodeBlocksFormattingExpected.kt", "KdocCodeBlocksFormattingTest.kt") }