kamadorueda / alejandra

The Uncompromising Nix Code Formatter
https://kamadorueda.github.io/alejandra/
The Unlicense
860 stars 41 forks source link

Feature Request: "strict" mode #352

Open the-argus opened 2 years ago

the-argus commented 2 years ago

I love alejandra, but my ideal formatter is completely uncompromising. That means that whitespace, including newlines, should not be interpreted by the formatter at all. There should be an algorithmically correct way of formatting a given nix set. For example, the following code is formatted by alejandra:

{
  test = {inherit (pkgs.lib) attrsets strings;};
}

However, if I add a newline, like so:

{
  test = {
  inherit (pkgs.lib) attrsets strings;};
}

And then format...

{
  test = {
    inherit (pkgs.lib) attrsets strings;
  };
}

I would prefer if there was a single interpretation of this code that alejandra subscribed to. I propose a --strict flag that chooses one of these. Frankly, I don't care much about which version --strict chooses, I just would like it to choose one. I don't want to be able to even think about formatting, I don't want there to be any choice that I can make that would change the format of my code.

Is this a welcome feature? If not, is there another formatter that does what I want?

jessestricker commented 2 years ago

Yes, please! There are widely used formatters for other languages that do this, too. Here are two of the top of my head:

I think this would be a great addition to alejandra.