3

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.

Pavan kumar C
  • 393
  • 1
  • 4
  • 15
  • What's your goal? To change Xcode's auto-formatting to match that particular SwiftLint setting? To make SwiftLint's suggestions match Xcode's auto-formatting? To make SwiftLint simply NOT CARE about the switch formatting? Or something else? – Bob Gilmore Feb 05 '21 at 16:34

2 Answers2

13

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

EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50
-1

When you get a SwiftLint Rule violation you can always go to this page for more information: https://realm.github.io/SwiftLint/switch_case_alignment.html

That shows you how to fix it. If you don't think you can easily fix it you can put an exemption in place to tell SwiftLint to ignore.

So you would just place this comment on the line above your switch statement:

// swiftlint:disable switch_case_alignment
Waxhaw
  • 599
  • 5
  • 9