8000 Sort set attributes alphabetically · Issue #276 · kamadorueda/alejandra · GitHub
[go: up one dir, main page]

Skip to content

Sort set attributes alphabetically #276

Open

Description

@KAction

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.

Activity

  1. kamadorueda commented on Apr 25, 2022

    @kamadorueda
    Owner

    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

  2. added
    type | feature request
    help wanted
    status | ready
    component | engine
    on Apr 25, 2022
  3. kamadorueda commented on Apr 28, 2022

    @kamadorueda
    Owner

    After #277 this should be more easy to implement

  4. adrian-gierakowski commented on Aug 28, 2022

    @adrian-gierakowski

    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.

  5. KAction commented on Aug 29, 2022

    @KAction
    Author

    I am cautious about sorting attrsets by default. For example, arguments to mkDerivation are supposed to be sorted in
    non-alphabetic order.

  6. 9999years commented on Jul 12, 2023

    @9999years
    Contributor

    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).

  7. adrian-gierakowski commented on Jul 12, 2023

    @adrian-gierakowski

    A command line flag to toggle sorting for all attrsets would also be nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component | enginehelp wantedstatus | readytype | feature request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0