Write a rule to alphabetize enum members by their key. This should handle both string-based enums and explicit numeric enums. Implicit numeric enums get a little tricky, because there might be code that is depending on their values which are generated by the current order (i.e. enums that are used in a database table)
String-based
enum Animals {
Dog = "dog",
Wolf = "wolf",
Cat = "cat",
}
will be transformed to:
enum Animals {
Cat = "cat",
Dog = "dog",
Wolf = "wolf",
}
Explicitly numeric
enum SortOrder {
DESC = 0,
ASC = 1,
}
will be transformed to:
enum SortOrder {
ASC = 1,
DESC = 0,
}
Implicitly numeric
For now, we can skip out on transforming implicit enums, but in the future, it might be nice to have an option that converts the enum to their explicit numeric values and then alphabetizes them, for example:
Write a rule to alphabetize enum members by their key. This should handle both string-based enums and explicit numeric enums. Implicit numeric enums get a little tricky, because there might be code that is depending on their values which are generated by the current order (i.e. enums that are used in a database table)
String-based
will be transformed to:
Explicitly numeric
will be transformed to:
Implicitly numeric
For now, we can skip out on transforming implicit enums, but in the future, it might be nice to have an option that converts the enum to their explicit numeric values and then alphabetizes them, for example:
will first be transformed to:
and then transformed to: