Skip to content

Commit

Permalink
Fixed CommentsFormatting for else blocks (#1743)
Browse files Browse the repository at this point in the history
- removed a removing of moved ASTNode
- reused ASTFactory
  • Loading branch information
nulls authored Sep 21, 2023
1 parent 05e7aa4 commit feeeee9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -154,13 +155,11 @@ class CommentsFormatting(configRules: List<RulesConfig>) : 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit feeeee9

Please sign in to comment.