You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some case it would be convenient to have attribute set to be automatically sorted (think something like all-packages.nix).
Sure, since attribute name can be arbitrary expression there is no way to handle every case, but for simple {b = 10; a = 15; } that should make sense. Clearly not every set should be sorted, so probably it should be opt-in with some comment or something like that.
I implemented this feature for nixfmt (NixOS/nixfmt#61), any change to see it in alejandra?
Also, I would love to have lists sorted too. Again, opt-in only, but automatically sorting buildInputs would be great.
This would be a very nice feature, I'm fan of sorting things
However, I think it's sane to implement this as an opt-in comment after the opening brace, since for instance the order of buildInputs matters sometimes and we cannot generalize
On the other hand, we can probably sort complex elements as well. Casting them to string would be enough
Sure, since attribute name can be arbitrary expression there is no way to handle every case
All expressions in place of attribute names could be grouped together at the beginning or end of the attrset, preserving the original order of the in which they appear in the code.
Personally I'd make sorting of attrset the default, and allow disabling it with a comment. And the opposite for lists ordering in lists is semantically significant.
Regarding sorting attrset style function arguments with: something to consider is to sort attributes with defaults as a separate group placed at the end of the set. And if #344 is implemented the user could choose how to group the attributes and each group could be sorted separately.
I am very interested in this feature but agree that it should be opt-in, ideally on a per-attrset basis (I'm imagining something like an # alejandra: sort comment at the beginning).
Activity
kamadorueda commentedon Apr 25, 2022
This would be a very nice feature, I'm fan of sorting things
However, I think it's sane to implement this as an opt-in comment after the opening brace, since for instance the order of
buildInputsmatters sometimes and we cannot generalizeOn the other hand, we can probably sort complex elements as well. Casting them to string would be enough
kamadorueda commentedon Apr 28, 2022
After #277 this should be more easy to implement
adrian-gierakowski commentedon Aug 28, 2022
All expressions in place of attribute names could be grouped together at the beginning or end of the attrset, preserving the original order of the in which they appear in the code.
Personally I'd make sorting of attrset the default, and allow disabling it with a comment. And the opposite for lists ordering in lists is semantically significant.
Regarding sorting attrset style function arguments with: something to consider is to sort attributes with defaults as a separate group placed at the end of the set. And if #344 is implemented the user could choose how to group the attributes and each group could be sorted separately.
KAction commentedon Aug 29, 2022
I am cautious about sorting attrsets by default. For example, arguments to
mkDerivationare supposed to be sorted innon-alphabetic order.
9999years commentedon Jul 12, 2023
I am very interested in this feature but agree that it should be opt-in, ideally on a per-attrset basis (I'm imagining something like an
# alejandra: sortcomment at the beginning).adrian-gierakowski commentedon Jul 12, 2023
A command line flag to toggle sorting for all attrsets would also be nice