kamadorueda / alejandra

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

Comments in inherits have extra newlines inserted. #407

Open bakhtiyarneyman opened 9 months ago

bakhtiyarneyman commented 9 months ago
paths = builtins.attrValues {
  inherit
    (pkgs)
    foo
    # This comment was supposed to be attached to bar.

    # But it gets split like this.

    bar
    baz
}
yajo commented 7 months ago

Besides the extra newlines, those lines are full of white spaces.

xceral commented 6 months ago

This happens with any trailing comment inside an expression:

{
  a = assert true; #
__
    1;
  b =
    foo #
____
    bar;
}

(superfluous spaces replaced with underscores for clarification)

ShamrockLee commented 3 months ago

I just experienced this issue.

kamadorueda commented 3 weeks ago

Perhaps this was fixed in 3.1.0?

https://kamadorueda.com/alejandra/?before=%7Bpaths+%3D+builtins.attrValues+%7B%0A++inherit%0A++++%28pkgs%29%0A++++foo%0A++++%23+This+comment+was+supposed+to+be+attached+to+bar.%0A++++%23+But+it+gets+split+like+this.%0A++++bar%0A++++baz%3B%0A%7D%3B%7D

Before:

{paths = builtins.attrValues {
  inherit
    (pkgs)
    foo
    # This comment was supposed to be attached to bar.
    # But it gets split like this.
    bar
    baz;
};}

After

{
  paths = builtins.attrValues {
    inherit
      (pkgs)
      foo
      # This comment was supposed to be attached to bar.
      # But it gets split like this.
      bar
      baz
      ;
  };
}