antfu / antfu/eslint-plugin-command
`/// keep-sorted` for `switch` statements
Open
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
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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