Files
pkl/pkl-formatter/src/test/files/FormatterSnippetTests/output/method-call-trailing-lambdas.pkl
Daniel Chao d29ae07e14 Fix formatting of argument lists (#1283)
This fixes several issues:

1. Leading/trailing line comments surrounding a lambda should make that
   lambda not "trailing", because the formatting otherwise looks bad and
   also isn't stable
2. Fix incorrect algorithm for detecting trailing lambda (currently,
   any number of lambdas makes the alg return `true`)
2025-11-03 09:15:58 -08:00

57 lines
1.1 KiB
Plaintext
Vendored

// multiple lambda arguments means argument list wraps
res1 =
foo.toMap(
(elem) -> elem.toString(),
(elem) -> elem.toString().split("").map((str) -> str + "hello").toSet(),
)
// new object and trailing lambda means argument list wraps
res2 =
foo.doFoo(
new Listing { 1; 2; 3 },
(elem) -> elem.toString().split("").map((str) -> str + "hello").toSet(),
)
// single trailing lambda is broken on its own
res4 =
foo.foldLeft("heeeeeeelloooooooooooooooooooooooooooooooooooooooooooooo", (elem) ->
elem.foooooooooooooooooooooooooooooooooooooooooooooooooooo
)
res5 =
ifNonNull((it) -> someFunctionCall(it as SomeReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongTypeName))
res6 =
ifNonNull((it) ->
someFunctionCall(it as SomeReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongTypeNameLonger)
)
res7 =
qux(
bar,
(a) -> hello // some comment
)
res8 =
qux(
// some comment
(a) -> bar,
)
res9 =
qux(
bar,
new {
bar = 1
} // some comment
)
res10 = (a) -> hello // some comment
res11 =
qux(
bar,
(a) -> hello
// some comment
)