SwiftFormat icon indicating copy to clipboard operation
SwiftFormat copied to clipboard

Can swiftformat align && operators in multi-line Equatable implementations like Xcode format?

Open topkim993 opened this issue 1 year ago • 2 comments

Background Xcode format automatically aligns && operators in multi-line Equatable implementations for better readability:

xcode format

struct Test: Equatable {
    let a: String
    let b: String
    let c: String
    let d: String

    public static func == (lhs: Test, rhs: Test) -> Bool {
        lhs.a == rhs.a &&
        lhs.b == rhs.b &&
        lhs.c == rhs.c
    }
}

However, using swiftformat --indent doesn't apply this alignment

swiftformat --indent

struct Test: Equatable {
    let a: String
    let b: String
    let c: String
    let d: String

    public static func == (lhs: Test, rhs: Test) -> Bool {
        lhs.a == rhs.a &&
            lhs.b == rhs.b &&
            lhs.c == rhs.c
    }
}

Question

Is there a way to configure swiftformat to align && operators in a way that matches Xcode format? If not, are there recommended workarounds or is this a potential feature for future updates?

topkim993 avatar Feb 23 '24 05:02 topkim993

I have the same problem, it's really bugging us because it causes a warning on SwiftLint. So please if anyone has an idea how to fix this it would be much appreciated. Thanks

image

sadaf-behbahani avatar Aug 13 '24 15:08 sadaf-behbahani

Could we get any updates here ?

sadaf-behbahani avatar Aug 14 '24 14:08 sadaf-behbahani