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

ktlint_standard_string-template-indent incompatbile with multi-dollar interpolation #2885

Closed
mgroth0 opened this issue Dec 1, 2024 · 3 comments · Fixed by #2888
Closed
Milestone

Comments

@mgroth0
Copy link
Contributor

mgroth0 commented Dec 1, 2024

It is a bit difficult to create a reproducer because the latest release of ktlint uses an embedded kotlin version that throws errors when it encounters $$ before a string. But if you use an embedded kotlin compiler version of 2.1.0 with ktlint 1.4.1 and run it on this

fun main() {
    $$"""
        hello world
    """.trimIndent()
}

You end up with

fun main() {
    $$
    """
        hello world
    """.trimIndent()
}

Which is a syntax error.

Disabling ktlint_standard_string-template-indent is preventing this.

@mgroth0 mgroth0 changed the title ktlint_standard_statement-wrapping incompatbile with multi-dollar interpolation ktlint_standard_string-template-indent incompatbile with multi-dollar interpolation Dec 1, 2024
@mgroth0
Copy link
Contributor Author

mgroth0 commented Dec 1, 2024

I don't know why originally it was another rule that seemed to be the cause, but I must have made some mistake. The cause is ktlint_standard_string-template-indent.

@paul-dingemans paul-dingemans added this to the 1.5 milestone Dec 1, 2024
@paul-dingemans
Copy link
Collaborator

Tnx for reporting.

@paul-dingemans
Copy link
Collaborator

As documented on https://kotlinlang.org/docs/strings.html#multi-dollar-string-interpolation the number of $ before the multiline string can vary. Using $$ means that single $ can be used in the string without it being used for interpolation. Using $$$ means that both $ and $$ can be used in the string. The multidollar prefix can be recorgnized in the AST as shown below:
Screenshot 2024-12-02 at 17 40 08

Note that compiler flag -Xmulti-dollar-interpolation needs to be enabled in order to use this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants