swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.24k stars 415 forks source link

BasicFormat indents closure parameter #1473

Open bnbarham opened 1 year ago

bnbarham commented 1 year ago
func testClosureParam() {
  var input = Parser("""
    foo(someClosure: { _ in
        return 1
    })
    """)
  let call = ExprSyntax.parse(from: &input)

  let formatted = call.formatted()
  assertStringsEqualWithDiff(formatted.description, """
    foo(someClosure: { _ in
        return 1
    })
    """)
}

Produces:

failed - Actual output (+) differed from expected output (-):
–foo(someClosure: { _ in
–    return 1
–})
+foo(someClosure: { _ in 
+        return 1
+    })

Note the double indent on return 1 and indent of }. Presumably we're always indenting on newlines within parameters of call expressions and then again from the code block.

ahoppen commented 1 year ago

rdar://107455223