A couple of issues with swift-format

swift-format wants this fragment (not what I do actually but a good example mimicking the actual code):

    let bar = 1.0
    let foo = bar
        .squareRoot()
        .magnitude

to be formatted as:

    let bar = 1.0
    let foo = // unwanted line break here
        bar
        .squareRoot()
        .magnitude

wrapping bar onto it's own line.
Intersetingly, if I change the order of the lines .squareRoot() and .magnitude then bar is fine to stay on the same line with let foo.

Is there a way to opt-out of line wrapping here?

I am using swift-format as a linter which results into unwanted [AddLines] add 1 line break warning for the above fragment. There are quite a few of such fragments and it would be impractical to disable each of them via swift-format-disable.


Somewhat similar, swift-format wants if / switch expressions to be on their own lines, so this:

let x = if ... {
    ...
} else {
    ...
}

is getting reformatted to:

let x = 
    if ... {
        ...
    } else {
        ...
    }

Not the end of the world but this as well I'd like to opt-out from "globally".

6 Likes