Kotlin / Kotlin/ktfmt

Brackets are formatted in a weird way when followed by chained calls

Open
#631 4 comments 0 reactions 1 assignee Claimed by @ptitjes View on GitHub
Dominant language
Kotlin
Stars
1.3k
Forks
116
Avg merge
4d 10h
Merged PRs (30d)
15

Description

Current behavior:

```kotlin
fun main() {
{
println("-----------------------------------")
println("-----------------------------------")
}
.invoke()

[
println("-----------------------------------"),
println("-----------------------------------"),
]
.map { it }

val a =
[
println("-----------------------------------"),
println("-----------------------------------"),
]
.map { it }
}
```

They just feel weird, and this problem would get worse and worse with the stabilization of collection literals because the pattern of constructing a list and do operations on it is so common. The current formatting is too weird to be acceptable.

Why don't we put ] ) } at the same indentation of the line containing [ ( {, and move the dot to align with ] ) } as well, so that everything would look nice?

```kotlin
fun main() {
{
println("-----------------------------------")
println("-----------------------------------")
}
.invoke()

[
println("-----------------------------------"),
println("-----------------------------------"),
]

[
println("-----------------------------------"),
println("-----------------------------------"),
]
.map { it }

val a =
[
println("-----------------------------------"),
println("-----------------------------------"),
]
.map { it }

run(
block = {
println("-----------------------------------")
println("-----------------------------------")
}
)
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.