Skip to content

useSortedEnumMembers (JavaScript)

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useSortedEnumMembers.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"useSortedEnumMembers": "on"
}
}
}
}

Sort the members of an enum in natural order.

Enforce a consistent natural sort order for TypeScript enum members with string initializers.

This rule sorts members in string enums so declarations stay predictable and easier to scan. Members that cannot be compared, such as computed names, are left in place and split the enum into sortable groups.

Members are sorted in a Natural order, meaning that uppercase letters come before lowercase letters (e.g. A < a < B < b) and numbers are compared to their numerical value (e.g. 9 < 10).

enum Status {
InProgress = 'In Progress',
Completed = 'Completed',
OnHold = 'On Hold',
Cancelled = 'Cancelled',
NotStarted = 'Not Started',
}
code-block.ts ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Source action diff:

1 1 enum Status {
2 - InProgress·=·'In·Progress',
2+ Cancelled·=·'Cancelled',
3 3 Completed = 'Completed',
4 - OnHold·=·'On·Hold',
5 - Cancelled·=·'Cancelled',
6 - NotStarted·=·'Not·Started',
4+ InProgress·=·'In·Progress',
5+ NotStarted·=·'Not·Started',
6+ OnHold·=·'On·Hold',
7 7 }
8 8

enum Status {
Cancelled = 'Cancelled',
Completed = 'Completed',
InProgress = 'In Progress',
NotStarted = 'Not Started',
OnHold = 'On Hold',
}