-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rule proposal: Sort Enum And Interface Keys #4008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
this should really be two separate rules: sort type properties and sort enum members. Why?
otoh
eg this is unsafe to auto-sort: enum Foo {
B,
A,
}
Foo.B === 1 /// === true
///// after sort /////
enum Foo {
A,
B,
}
Foo.A === 1 /// === false Other example of how you might want to sort an enum: // sorted by value
enum Foo {
CLIArgFoo = 1,
CLIArgBar = 2,
CLIArgBaz = 3,
}
// sorted by key
enum Foo {
CLIArgBar = 2,
CLIArgBaz = 3,
CLIArgFoo = 1,
} |
That's definitely better, yes, |
I stumbled upon this eslint plugin which seems to take care of these cases https://github.com/azat-io/eslint-plugin-perfectionist Note that I have not tested this plugin myself. Since ts-eslint tries to shy away from stylistic rules, is these rules still something that project wants? |
Aha, I've been using that plugin in http://github.com/JoshuaKGoldberg/template-typescript-node-package. It's great. cc @azat-io 😄 Let's close this out, yes. Per https://typescript-eslint.io/linting/troubleshooting/formatting we're trying not to take on additional responsibility around stylistic concerns. And the plugin does a great job on its own. Thanks for the spot! |
Description
It would be great it a rule existed where interfaces and enum keys can be sorted.
If this is not considered a thing that might be added, feel free to close this issue
Fail
Pass
The text was updated successfully, but these errors were encountered: