Skip to content

Commit

Permalink
### Whats Added:
Browse files Browse the repository at this point in the history
    * corrected code StringLiteral
    * added test

### Issue(#811)
  • Loading branch information
Arrgentum committed Jun 6, 2022
1 parent 2b0a521 commit 32c646c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
it == "trimMargin()"
} == true) {
fixStringLiteral(whiteSpace, expectedIndent, actualIndent)
println(nextNodeDot)
}
}

Expand All @@ -242,14 +243,19 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
expectedIndent: Int,
actualIndent: Int
) {
val textIndent = " ".repeat(expectedIndent + INDENT_SIZE)
val templateEntries = whiteSpace.node.treeNext.firstChildNode.getAllChildrenWithType(LITERAL_STRING_TEMPLATE_ENTRY)
templateEntries.forEach { node ->
val nextNodeDot = if (whiteSpace.node.treeNext.elementType == DOT_QUALIFIED_EXPRESSION) {
whiteSpace.node.treeNext
} else {
whiteSpace.node.treeNext.getFirstChildWithType(DOT_QUALIFIED_EXPRESSION)
}
val textIndent = " ".repeat(actualIndent + INDENT_SIZE)
val templateEntries = nextNodeDot?.getFirstChildWithType(STRING_TEMPLATE)?.getAllChildrenWithType(LITERAL_STRING_TEMPLATE_ENTRY)
templateEntries?.forEach { node ->
if (!node.text.contains("\n")) {
fixFirstTemplateEntries(node, textIndent, actualIndent)
}
}
(templateEntries.last().firstChildNode as LeafPsiElement)
(templateEntries?.last()?.firstChildNode as LeafPsiElement)
.rawReplaceWithText(" ".repeat(expectedIndent) + templateEntries
.last()
.firstChildNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ class IndentationRuleFixTest : FixTestBase("test/paragraph3/indentation",
@Test
@Tag(WarningNames.WRONG_INDENTATION)
fun `multiline string`() {
fixAndCompare("MultilionStringTest.kt", "MultilionStringTest.kt")
fixAndCompare("MultilionStringExpected.kt", "MultilionStringTest.kt")
}
}

0 comments on commit 32c646c

Please sign in to comment.