Skip to content

Commit

Permalink
Ignore multi dollar string interpolation prefix in `string-template-i…
Browse files Browse the repository at this point in the history
…ndent` rule (#2888)

Closes #2885
  • Loading branch information
paul-dingemans authored Dec 2, 2024
1 parent 50dd698 commit c50c237
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class StringTemplateIndentRule :
?.takeIf { it.elementType == ElementType.EQ }
?.closingParenthesisOfFunctionOrNull()
?.prevLeaf()
?.let { it.isWhiteSpaceWithNewline() }
?.isWhiteSpaceWithNewline()
?: false

private fun ASTNode.closingParenthesisOfFunctionOrNull() =
Expand Down Expand Up @@ -292,7 +292,13 @@ public class StringTemplateIndentRule :
indent: String,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision,
) {
val firstNodeAfterOpeningQuotes = node.firstChildNode.nextLeaf() ?: return
val firstNodeAfterOpeningQuotes =
node
// The string template can start with an INTERPOLATION_PREFIX (multi dollar string interpolation, see
// https://kotlinlang.org/docs/strings.html#multi-dollar-string-interpolation), which is to be skipped.
.findChildByType(OPEN_QUOTE)
?.nextLeaf()
?: return
if (firstNodeAfterOpeningQuotes.text.isNotBlank()) {
emit(
firstNodeAfterOpeningQuotes.startOffset + firstNodeAfterOpeningQuotes.text.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,16 @@ class StringTemplateIndentRuleTest {
""".trimIndent()
stringTemplateIndentRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2885 - Given a multiline string template prefix with a multi-dollar interpolation prefix`() {
val code =
"""
val foo =
$$$MULTILINE_STRING_QUOTE
Some text
$MULTILINE_STRING_QUOTE.trimIndent()
""".trimIndent()
stringTemplateIndentRuleAssertThat(code).hasNoLintViolations()
}
}

0 comments on commit c50c237

Please # to comment.