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

Indent code in string template conflicts with default IntelliJ IDEA formatting #1562

Closed
paul-dingemans opened this issue Jul 31, 2022 · 2 comments · Fixed by #1682
Closed

Comments

@paul-dingemans
Copy link
Collaborator

Expected Behavior

Code below is formatted with IntelliJ IDEA default formatting and should be accepted by KtLint without changes:

fun foo1() =
    "Sum of uneven numbers = ${
        listOf(1, 2, 3)
            .filter { it % 2 == 0 }
            .sum()
    }"

fun foo2() = "Sum of uneven numbers = ${
    listOf(1, 2, 3)
        .filter { it % 2 == 0 }
        .sum()
}"

Observed Behavior

Klint 0.46.1 reports following violations:

$ ktlint-0.46.1 --relative
src/main/kotlin/Foo.kt:3:1: Unexpected indentation (8) (should be 4) (indent)
src/main/kotlin/Foo.kt:4:1: Unexpected indentation (12) (should be 8) (indent)
src/main/kotlin/Foo.kt:5:1: Unexpected indentation (12) (should be 8) (indent)
src/main/kotlin/Foo.kt:9:1: Unexpected indentation (4) (should be 0) (indent)
src/main/kotlin/Foo.kt:10:1: Unexpected indentation (8) (should be 4) (indent)
src/main/kotlin/Foo.kt:11:1: Unexpected indentation (8) (should be 4) (indent)

which result in code:

fun foo1() =
    "Sum of uneven numbers = ${
    listOf(1, 2, 3)
        .filter { it % 2 == 0 }
        .sum()
    }"

fun foo2() = "Sum of uneven numbers = ${
listOf(1, 2, 3)
    .filter { it % 2 == 0 }
    .sum()
}"

Your Environment

  • Version of ktlint used: 0.46.1
@paul-dingemans
Copy link
Collaborator Author

Solved by #1682

@paul-dingemans
Copy link
Collaborator Author

Closed by #1682

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

Successfully merging a pull request may close this issue.

1 participant