-
Notifications
You must be signed in to change notification settings - Fork 81
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
Sort identifiers in deriving
clauses?
#968
Comments
Sorting of this kind of thing is doable and perhaps desirable. The problem is that Ormolu relies on source span information in order to both control the layout (single line vs multiline) and to insert comments. The latter logic is quite complicated and it doesn't like things to move around and be out of order compared to the original input. One example where we went ahead and implemented sorting is explicit module export/import lists. This was a good change, but there are still some unsolved problems with that to this day (see, e.g. #469). Not sure we should do more of this. |
What if the identifiers were only sorted when there were no comments at all in the list of derived type classes? That way the common case of a flat list of names would be sorted. But if there was a comment anywhere in there, the order would be left alone. -- would be sorted
data T = C deriving (Show, Eq) -- would not be sorted
data T = C deriving (Show, {- x -} Eq) That also allows for some fancier logic to come later, if it's desired. For example comments could move with their associated identifiers. Or comments could set off separate blocks, which are sorted independently. |
To me this doesn't seem satisfactory enough—complex logic and more inconsistent behavior for a questionable gain. |
Gotcha. Sounds like this won't be supported in Ormolu then. Thanks for considering it! |
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
This adds two configuration options for sorting a) types in deriving clauses, and b) deriving clauses themselves. Fixes tweag/ormolu#968
Describe the solution you'd like
I would like it if Ormolu sorted identifiers in
deriving
clauses. For example:As far as I know, different orderings of the identifiers in a
deriving
clause are equivalent, so this should be a safe transformation to make. It would reduce noise in diffs, especially with multi-linederiving
clauses.I don't have a strong opinion about how exactly things should be sorted. Alphabetical is a natural choice. Qualified identifiers make things a bit trickier; it's not clear if
A.C
should come before or afterB
.Describe alternatives you've considered
Currently I make a best effort to sort things manually. It's tedious and error prone.
Additional context
I think this is similar in spirit to how Ormolu sorts imports.
The text was updated successfully, but these errors were encountered: