🔧 The --fix
option on the command line can automatically fix the problems
reported by this rule.
Sorts TypeScript string enums alphabetically and case insensitive in ascending order.
Examples of incorrect code for this rule:
enum Fruit {
Orange = "orange",
Apple = "apple",
Grape = "grape",
}
Examples of correct code for this rule:
enum Fruit {
Apple = "apple",
Grape = "grape",
Orange = "orange",
}
This rule has an options object with the following defaults.
{
"sort/string-enums": ["error", { "caseSensitive": false, "natural": true }]
}
If true
, enforce string enums to be in case-sensitive order.
If true
, enforce string enums to be in natural order. Natural order compares
strings containing combination of letters and numbers in the way a human being
would sort. For example, A10
would come after A3
when using natural
ordering.
This rule is a formatting preference and not following it won't negatively affect the quality of your code. If alphabetizing string enums isn't a part of your coding standards, then you can leave this rule off.