Files
pkl/pkl-formatter/src/test/files/FormatterSnippetTests/input/line-breaks3.pkl
Daniel Chao d8adb28dd1 Respect line breaks in operator chains and argument lists (#1268)
If an operator chain or method call is multiline, keep those newlines
in the formatted output.

Help preserve code like:

```
foo
  |> (it) -> it + 2
  |> (it) -> it / 2
```
2025-11-02 21:51:37 -08:00

59 lines
763 B
Plaintext
Vendored

// respect line breaks on:
// * operator chains
// * argument lists in method calls
//
// only look for line breaks on either side of the operator, or the comma.
res1 =
foo
* bar
* baz
res2 = foo
|> bar + bar
|> baz
res3 = foo
|> bar
+ baz
|> qux
res4 = foo(
(it) -> it + 1,
(it) -> it + 2
)
res5 = foo(
1,
2, 3, 4
)
// don't respect newlines right after opening paren and closing paren
res6 = foo.bar(
1, 2, 3
)
// only respect newlines on either side of a binary operator (we still want to inline `bar(3)` here).
res7 = foo + bar(
3
) + baz
// only the newlines after each "entry" are respected
res8 = Map(
1, 2,
3, 4
)
res9 = Map(
1,
2,
3, 4
)
res10 = foo(1
,2
,3)
res11 = foo +
bar +
baz