Open mohammadalipak opened 2 years ago
Hmmm interesting request which could work in some cases. The main case for enum is that you don't define anything:
enum Fruit {
WATERMELON,
APPLE,
BANANA
}
in which case they are in order since enum
assigns numbers in order.
We could technically sort keys with assigned values as long as they are adjacent:
enum Fruit {
WATERMELON,
BANANA = 'BANANA',
APPLE = "APPLE",
}
As they wouldn't impact the inferred value provided to keys without values. This would resolve your ticket.
But to respond to your statement "It seems like sortier ignores the Typescript enums. It should be sorting them by keys." the answer is yes because without values, the order of an enum is crucial to it's generated value hence why it was ignored.
However you bring up a good point that if the values are defined, we should be able to change the order. Let me think on this to see if there are scenarios I'm missing.
I'd welcome a PR here, should be relatively straight forward:
src\language-js
or just copy an existing one like sortJsxElement
and name it sortEnumimport { EnumDeclaration } from "typescript";
.
Language
Typescript
Sample input source code
Expected output
Actual output
It seems like sortier ignores the Typescript enums. It should be sorting them by keys.