google / google/google-java-format

Conditional OpenOp / CloseOp

オープン
#556 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
6.2k
フォーク
937
平均マージ
6分
マージ済み PR(30日)
3

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。