google / google/google-java-format

Conditional OpenOp / CloseOp

Abierto
#556 2 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
6.2k
Forks
937
Merge medio
6 min
PR fusionados (30 d)
3

Descripción

In `ktfmt`, I'd like to format the following:

```
fun longName() = coroutineScope {
foo()
//
}
```

but if it doesn't fit in a single line, I'd like to get

```
fun longName() =
coroutineScope {
foo()
//
}
```

I only managed to create the first form by _not_ wrapping the lambda in an `OpenOp` / `CloseOp` block, while the second form arises naturally from such a block around `coroutine { … }`.

One way to solve this is to create a conditional `OpenOp` / `CloseOp`, similarly to `Indent.If`, and then emit a block that materializes only if there had been a break after the `=`.

What do you think?

(I admit this isn't super clear, let me know if I should make another attempt at explaining this)

cc @cushon @bethcutler

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.