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

Ignore multi dollar string interpolation prefix in string-template-indent rule #2888

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading