Search code examples
swiftswitch-statementswiftlint

Switch case formatting issue with SwiftLint


My switch case is auto formatted when i do Cntrl + i , like below

switch someBool {
    ↓case true:
        print("success")
    ↓case false:
        print("failed")
}

but its throws a lint warning Switch and Case Statement Alignment Violation: Case statements should vertically align with their enclosing switch statement. (switch_case_alignment)

I have go manually format like below

switch someBool {
case true:
    print('red')
case false:
    print('blue')
}

but this changes as soon as i do Cntrl+I

Any suggestions are welcome. Thank you.


Solution

  • You can adjust that setting on Xcode with the following checkbox. I think it comes unchecked by default, which should match SwiftLint's default rules.

    Xcode indentation settings