Skip to content
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

Canonincal order could group derives by crate #33

Open
Sagebati opened this issue Oct 7, 2024 · 1 comment
Open

Canonincal order could group derives by crate #33

Sagebati opened this issue Oct 7, 2024 · 1 comment

Comments

@Sagebati
Copy link

Sagebati commented Oct 7, 2024

Hi,

I come across your project and it's great, I find the feature to sort derives really usefull. I think it could be improved by grouping derives by their crate and then order them, it could be great. What do you think ? Would you be interested in a PR with this feature ?

@maksym-arutyunyan
Copy link
Owner

Grouping by crates might be difficult to achieve because often crates are not stated explicitly. Figuring out the right crate in this case increases the complexity significantly. Here's a table of derive traits by their frequency in a big repo, you can see similar traits are used with and without crate names.

Adding another very specific type of sorting to already provided Canonical and Alphabetical might bring more harm than good -- more possibility everyone to go different directions. My preference is that rustfmt implements a single one and only right order and make everyone stick to it. Unfortunately it's not the case yet, so I implemented it in my tool as a workaround. Maybe even 2 is too many :)

... but! there might be an option for a universal 3rd one -- Custom when user provides their own priority list. Then everyone can go wild.

As a bottom line:

  • no, I wouldn't want to implement 'group by crate' option, since it's too specific
  • maybe I would be interested to add Custom option which allows everyone to use their own order, but I am hesitant because of 'pandora box' issue
  • and lastly I don't have capacity at the moment to work on this, so it's rather no

As a workaround you may want to look at cargo-sort-derives crate which has Custom option. But it has its own issues (like sorting everything by regex including comments and string lines).

@maksym-arutyunyan maksym-arutyunyan changed the title Canincal order could group derives by crate Canonincal order could group derives by crate Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants