Swiftformat: SortedSwitchCases Bug?

Created on 25 Nov 2020  路  3Comments  路  Source: nicklockwood/SwiftFormat

I am sure you are familiar with the age 'ol alphabetic sorting on numbers not working out so well... I suspect this is something we can account for here?
There is only one of these in our code, but it stood out when I made the PR with this rule being enforced and I figured I better ask about it, too. I would guess we can see if the variable we are switching on is numeric and sort numerically, else we sort as it does now?

func numberOfDaysPerMonth(month: Int) -> Int {
  switch month {
    case 1, 3, 5, 7, 8, 10, 12:
      return 31

became

func numberOfDaysPerMonth(month: Int) -> Int {
  switch month {
    case 1, 10, 3, 5, 7, 8, 12:
      return 31
bug fixed in develop

All 3 comments

馃憤 I'll get that fixed

By the way, we are a bit baffled how 12 remained at the end and did not get moved, too, assuming a standard ASCII sorting. I glanced at the code for this and it appears to grab the last token next to the colon, but someone else asked if it is anchored. I can only speculate it has to do with the range tokens around nextStart and nextEnd because I mess up that stuff all the time.

@PompeiaPaetenari fixed in 0.47.5.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

soranoba picture soranoba  路  3Comments

meherkasam picture meherkasam  路  4Comments

MaxDesiatov picture MaxDesiatov  路  3Comments

mdiep picture mdiep  路  3Comments

DagAgren picture DagAgren  路  4Comments