useSortedEnumMembers
Summary
Section titled “Summary”- Diagnostic Category:
assist/source/useSortedEnumMembers - Sources:
- Inspired from
@graphql-eslint/alphabetize
- 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 }}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 an enum in natural order.
Enforce a consistent natural sort order for GraphQL enum values.
Keeping enum values sorted makes schema definitions easier to review and maintain, especially as enums grow over time.
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).
Examples
Section titled “Examples”Invalid
Section titled “Invalid”enum Role { SUPER_ADMIN ADMIN USER GOD}code-block.graphql:1:1 assist/source/useSortedEnumMembers FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The members of the enum Role are not sorted.
> 1 │ enum Role {
│ ^^^^^^^^^^^
> 2 │ SUPER_ADMIN
> 3 │ ADMIN
> 4 │ USER
> 5 │ GOD
> 6 │ }
│ ^
7 │
ℹ Safe fix: Sort the enum members.
1 1 │ enum Role {
2 │ - ··SUPER_ADMIN
3 │ - ··ADMIN
4 │ - ··USER
5 │ - ··GOD
2 │ + ··ADMIN
3 │ + ··GOD
4 │ + ··SUPER_ADMIN
5 │ + ··USER
6 6 │ }
7 7 │
enum Role { ADMIN GOD SUPER_ADMIN USER}Related links
Section titled “Related links”Summary
Section titled “Summary”- 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 }}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 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).
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.