-
Notifications
You must be signed in to change notification settings - Fork 922
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
Feature request: alphabetic sorting of struct/enum fields #3422
Comments
On a related note, sorting the arms of a match based on the order in the |
@mwillsey you mean to reflect the enum's order on the match ? I don't think that is possible since we have only information coming from the AST |
In addition to being able to sort fields, it would also be nice to be able to sort top-level items (Structs, Traits, etc.) in a file. |
This would be nice!! |
I would also like to see this for methods of a trait. |
I hope this will be added someday. It will save the minutes spent sorting them manually. |
👍 for opt-in to apply this to all structs, enums, unions, and simple match statements on enums, except |
Another +1 here, I already naturally try to sort stuff alphabetically, so this would be a time saver and ensure consistency. I also +1 having it optionally available for top-level items as @jeremyBanks suggested. |
fwiw jetbrains ides have a sort lines command (select fields, maybe with opt+up arrow idk for windows, double press shift, type sort lines, hit enter or assign a keybind to sort lines) not ideal but better than manual sorting |
+1, I need this as I'm working with massive structs to accept an API's response! |
I've asked for this 3-years ago. Oh my... 🤦♂️🤦♂️🤦♂️ |
The complexity is in, ‘Whenever the order of a struct or enum would be completely irrelevant’ ... |
@sanmai-NL I don't think this is a real concern, as the OP suggests, this can be done via an opt-in attribute ( |
You presuppose users would want to invest time in specifying such an attribute. And what about |
Is it possible to have the opt-in attribute ( |
Yes. I know I would use it in a few places. It would be too annoying as an opt-out (
What about them? If you added the |
@WaffleLapkin not sure what design you intended, but fields should be sorted by default, and this will generally break |
why not implement this as an opt-in rule and also a tag (since rustfmt doesnt support rules being enabled per scope like in clippy yet)? that way people can opt-in to the rule and opt-out for scopes they dont want with for some libraries, such as api wrappers, not having an option to enable the feature globally would require us to add |
Whenever the order of a struct or enum would be completely irrelevant, I like to keep them in alphabetic order. However, this gets slightly annoying to maintain when adding new fields. Therefore I propose an optional automatic sorting attribute, think
#[rustfmt::sort]
.My first idea was to create a clippy lint for this, but having this done automatically would be the best.
The text was updated successfully, but these errors were encountered: