nicklockwood / SwiftFormat

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

Opening brace moved to new line after multiline if let despite allman option set to false #1685

Closed Chris75539 closed 2 months ago

Chris75539 commented 2 months ago

Hi there,

I just noticed that the opening brace following a multiline if-let-condition is moved to the next line although the allman option is set to false.

Example:

let var1: Int?
let var2: Int?
if let var1 = var1,
   let var2 = var2 {
    printf("\(var1 + var2)")
}

turns into

let var1: Int?
let var2: Int?
if let var1 = var1,
   let var2 = var2
{
    printf("\(var1 + var2)")
}

I'm not sure if it is intended that way, but it contradicts the opening_brace rule of SwiftLint and I didn't find a workaround except for either deactivating the SwiftFormat braces rule or the SwiftLint opening_brace rule.

Of course the if let in the given example could be written in one line but I had several cases in my code where one line was not enough.

This happens with Xcode 15.3 and both the Xcode extension and the Swift Package Manager plugin of version 0.53.7.

Thanks and best regards Chris

nicklockwood commented 2 months ago

@Chris75539 you can add --disable wrapMultilineStatementBraces to fix this

Chris75539 commented 2 months ago

@nicklockwood thanks for your quick reply. I guess that solves my problem. I hadn't considered that option before.