Skip to content

/// keep-sorted for switch statements #17

@GauBen

Description

@GauBen

Clear and concise description of the problem

Hey there, I'm back with another suggestion: /// keep-sorted for switch statements. The idea comes from this file

Suggested solution

Basic

/// keep-sorted
switch (x) {
  case "b":
    doB();
    break
  case "a":
    doA();
    break;
}

// ->

/// keep-sorted
switch (x) {
  case "a":
    doA();
    break
  case "b":
    doB();
    break;
}

Complex/weird

/// keep-sorted
switch (x) {
  case "fallback":
    falling();
  case "c":
  case "b":
    common();
    break;
  case "d":
  case "a":
    aOrD();
    break;
}

// ->

/// keep-sorted
switch (x) {
  case "a": // `a` comes before `fallback`
  case "d":
    aOrD();
    break;
  case "fallback":
    falling();
  case "b":
  case "c":
    common();
    break;
}

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions