useSortedEnumMembers (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.5.0 - Diagnostic Category:
assist/source/useSortedEnumMembers - Sources:
- Inspired from
perfectionist/sort-enums - Inspired from
typescript-sort-keys/string-enum
- Inspired from
How to enable in your editor
Section titled “How to enable in your editor”{ "editor.codeActionsOnSave": { "source.action.useSortedEnumMembers.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useSortedEnumMembers.biome": true, "source.fixAll.biome": true }}
Use the source action code
source.action.useSortedEnumMembers.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "useSortedEnumMembers": "on" } } }}Description
Section titled “Description”Sort the members of a string-valued TypeScript enum.
The action uses natural order: uppercase
letters come before lowercase letters (A before a), and numbers are compared by value
(item9 before item10). This keeps enum declarations predictable and easy to scan.
A member with a computed name cannot be compared reliably. The action leaves that member in place and sorts the comparable members on each side independently.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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',}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.