realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

Rule Request: Line break in between case statements #5512

Closed JulesMoorhouse closed 3 months ago

JulesMoorhouse commented 3 months ago

New Issue Checklist

New rule request

To make switch statements more readable.

triggering:

switch dayOfWeek {
  case 1:
    print("Sunday")
  case 2:
    print("Monday")
  case 3:
    print("Tuesday")
  case 4:
    print("Wednesday")
  case 5:
    print("Thursday")
  case 6:
    print("Friday")
  case 7:
    print("Saturday")
  default:
    print("Invalid day")
}

not triggering:

switch dayOfWeek {
  case 1:
    print("Sunday")

  case 2:
    print("Monday")

  case 3:
    print("Tuesday")

  case 4:
    print("Wednesday")

  case 5:
    print("Thursday")

  case 6:
    print("Friday")

  case 7:
    print("Saturday")

  default:
    print("Invalid day")
}

I've tried to write a regex to do this, but you cannot use quantifiers like *, +, or {n,m} inside a lookbehind assertion

Thanks,

Jules.

mildm8nnered commented 3 months ago

I think that rule already exists: https://realm.github.io/SwiftLint/vertical_whitespace_between_cases.html

JulesMoorhouse commented 3 months ago

Thanks

SimplyDanny commented 3 months ago

I think that rule already exists: https://realm.github.io/SwiftLint/vertical_whitespace_between_cases.html

Oh, I didn't have that on my radar. 😅

mildm8nnered commented 3 months ago

I was just setting up SwiftLint on a new project yesterday, and had to disable that rule. :-)