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

Formatting big string templates #1233

Closed
chrihunstad opened this issue Sep 13, 2021 · 3 comments
Closed

Formatting big string templates #1233

chrihunstad opened this issue Sep 13, 2021 · 3 comments

Comments

@chrihunstad
Copy link

In our projects we create fairly big string templates to generate our SQL queries. However, autoformatting these strings rarely end up looking good.

Expected Behavior

    fun indentTest(ids: List<String>?) = """
        SELECT * foo
        FROM bar
        WHERE
          ${when (ids) {
            null -> "TRUE"
            emptyList<String>() -> "FALSE"
            else -> "some_ids IN (:doc_ids)"
          }}
    """.trimIndent()

Observed Behavior

    fun indentTest(ids: List<String>?) = """
        SELECT * foo
        FROM bar
        WHERE
          ${
        when (ids) {
            null -> "TRUE"
            emptyList<String>() -> "FALSE"
            else -> "some_ids IN (:doc_ids)"
        }
    }
    """.trimIndent()

Your Environment

  • Version of ktlint used: 0.42.1
@chrihunstad
Copy link
Author

Right now I am disabling the indent rule for all our files containing SQL-queries. Is there any way to just ignore multiline strings in .editorconfig instead?

@paul-dingemans
Copy link
Collaborator

There is no way to disable indentations of the multiline strings only. The problem seems to be identical to a situation which I had myself a few weeks ago. A complex ${...} like your example gets additional newline while this does not happen a simple reference of a object property. I am not sure whether that is a regression bug or something which never has been implemented.

@paul-dingemans
Copy link
Collaborator

This issue will be resolved when this #1052 is merged.

@romtsn romtsn closed this as completed Oct 24, 2021
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

No branches or pull requests

3 participants