nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 639 forks source link

Open brace unexpectedly wrapped in `guard` statement #1188

Closed calda closed 2 years ago

calda commented 2 years ago

When testing develop on our codebase, I encountered one issue where the open brace of a closure in a guard statement would be wrapped unexpectedly. Here's a test case that fails on develop (which I'd expect to pass):

func testOpenBraceAfterEqualsInGuardNotWrapped() {
    let input = """
    guard
        let foo = foo,
        let bar: String = {
            nil
        }()
    else { return }
    """

    let options = FormatOptions(
        wrapArguments: .beforeFirst,
        closingParenOnSameLine: true
    )
    testFormatting(for: input, rules: [FormatRules.wrapMultilineStatementBraces, FormatRules.wrap],
                   options: options, exclude: ["indent", "redundantClosure"])
}

here's a commit that includes that test case: https://github.com/calda/SwiftFormat/commit/8d121bfb378a84fed27f1423a6efae156a50a8b4

nicklockwood commented 2 years ago

@calda fixed in 0.49.10