Skip to content

Commit

Permalink
Make empty inherit's more consistent and convenient
Browse files Browse the repository at this point in the history
This might happen if you temporarily remove all inherits, in which case
the formatter shouldn't remove the spacing that was there.

E.g. I might have this initially

    inherit a b;

    inherit
      c
      d
      ;

removing all the bindings gives me

    inherit ; # I already have the space that I'll need

    inherit # I can just press enter here to add one
      ;

which shouldn't be changed, because it's easier like this to insert new
entries again, compared to

    inherit;

This also makes it more consistent with the parent commit's change
  • Loading branch information
infinisil committed Jul 19, 2024
1 parent 5862780 commit 2c0d0d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ instance Pretty Binder where
pretty (Inherit inherit Nothing ids semicolon) =
group $
pretty inherit
<> ( if null ids
then pretty semicolon
else sep <> nest (sepBy sep ids <> nosep <> pretty semicolon)
)
<> sep
<> nest (sepBy sep ids <> nosep <> pretty semicolon)
where
-- Only allow a single line if it's already on a single line and has few enough elements
(sep, nosep) = if sourceLine inherit == sourceLine semicolon && length ids < 4 then (line, line') else (hardline, hardline)
Expand Down
5 changes: 3 additions & 2 deletions test/diff/inherit/out.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
# empty inherit o.O
inherit;
inherit ;
inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
}
{
Expand Down Expand Up @@ -83,7 +83,8 @@
}

{
inherit;
inherit
;
inherit
a
;
Expand Down

0 comments on commit 2c0d0d1

Please sign in to comment.