antfu / antfu/eslint-plugin-command

`/// keep-sorted` for `switch` statements

Open
#17 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
371
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by studying the linked src/utils/devenv.ts example and the repository's existing command behavior. Define how basic and grouped switch cases should be ordered, including fallthrough and comments, then add coverage for the shown examples. Done means the keep-sorted command consistently produces the requested ordering without changing case bodies.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.