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`)
This commit is contained in:
Daniel Chao
2025-11-03 09:15:58 -08:00
committed by GitHub
parent 4226c21a42
commit d29ae07e14
6 changed files with 82 additions and 33 deletions

View File

@@ -19,3 +19,27 @@ res4 = foo.foldLeft(
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
)

View File

@@ -76,8 +76,9 @@ local function render(currentIndent: String) =
items: List<Item> =
allItems
.filter((item) ->
badItems.containsKey(item) // some line comment
|| item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
.filter(
(item) ->
badItems.containsKey(item) // some line comment
|| item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
)
.sortBy((item) -> item.name)

View File

@@ -25,3 +25,32 @@ 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
)