eslint-plugin-perfectionist icon indicating copy to clipboard operation
eslint-plugin-perfectionist copied to clipboard

Feature: (sort-switch-case) Would you consider sorting the `case` blocks in a `switch` statement?

Open u3u opened this issue 11 months ago • 3 comments

Describe the rule

Can you add a sort-switch-case rule? It will sort the case statements, their order does not affect the execution result, but it can improve readability, reduce code merge conflicts, and eliminate the need to worry about their order when writing code.

Code example

Input

switch (type) {
  case 'save': {
    break;
  }

  case 'edit': {
    break;
  }

  default:
  case 'close': {
    break;
  }
}

Output

switch (type) {
  default:
  case 'close': {
    break;
  }

  case 'edit': {
    break;
  }

  case 'save': {
    break;
  }
}

Additional comments

No response

Validations

  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

u3u avatar Aug 04 '23 14:08 u3u