Skip to content

Commit

Permalink
Rework inherit statements
Browse files Browse the repository at this point in the history
- The (from) case needs to be improved
- Somehow it indents the comments *after* the statement now, no idea why or how to fix
  • Loading branch information
piegamesde committed May 5, 2023
1 parent cd0acd3 commit 6ea9841
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 249 deletions.
13 changes: 8 additions & 5 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ instance Pretty Selector where
= pretty dot <> pretty sel
<> hardspace <> pretty kw <> hardspace <> pretty def

-- in attrsets and let bindings
instance Pretty Binder where
-- `inherit bar` statement
pretty (Inherit inherit Nothing ids semicolon)
= base $ group (pretty inherit <> softline
<> nest 2 (sepBy softline ids)) <> pretty semicolon
= base $ group (pretty inherit <> hardspace <> line'
<> nest 2 (sepBy (hardspace <> line') ids <> line' <> pretty semicolon))

-- `inherit (foo) bar` statement
pretty (Inherit inherit source ids semicolon)
= base $ group (pretty inherit <> hardspace
<> pretty source <> line
<> nest 2 (sepBy softline ids)) <> pretty semicolon
= base $ group (pretty inherit <> hardspace <> line'
<> nest 2 (pretty source <> hardspace <> line' <> sepBy (hardspace <> line') ids <> line' <> pretty semicolon))

-- `foo = bar`
pretty (Assignment selectors assign expr semicolon)
= base $ group (hcat selectors <> hardspace
<> nest 2 (pretty assign <> softline <> pretty expr))
Expand Down
25 changes: 18 additions & 7 deletions test/diff/idioms_lib_2/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,24 @@ rec {
f a;

# Pull in some builtins not included elsewhere.
inherit (builtins)
pathExists readFile isBool isInt isFloat add sub lessThan seq deepSeq
genericClosure;

## nixpkgs version strings

# Returns the current full nixpkgs version number.
inherit
(builtins)
pathExists
readFile
isBool
isInt
isFloat
add
sub
lessThan
seq
deepSeq
genericClosure
;

## nixpkgs version strings

# Returns the current full nixpkgs version number.
version = release + versionSuffix;

# Returns the current nixpkgs release number as string.
Expand Down
38 changes: 25 additions & 13 deletions test/diff/inherit/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,46 @@
}
{ inherit b d; }
{
inherit b d # e
;
inherit
b
d # e
;
}
{
inherit b # c
d;
inherit
b # c
d
;
}
{
inherit b # c
inherit
b # c
d # e
;
;
}
{
inherit # a
b d;
b
d
;
}
{
inherit # a
b d # e
;
b
d # e
;
}
{
inherit # a
b # c
d;
d
;
}
{
inherit # a
b # c
d # e
;
;
}
{
inherit # test
Expand All @@ -47,8 +56,11 @@
c # test
d # test

e f
e
f

g h;
g
h
;
}
]
12 changes: 8 additions & 4 deletions test/diff/inherit_blank_trailing/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
c # test
d # test

e f
e
f

g h;
g
h
;
}
{
inherit a # mixed trivialities
inherit
a # mixed trivialities

# comment 1
# comment 2
Expand All @@ -24,6 +28,6 @@
# comment 1
# comment 2
# comment 3
;
;
}
]
13 changes: 8 additions & 5 deletions test/diff/inherit_comment/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
inherit # eeby deeby
a
# b
c;
c
;

# https://github.com/kamadorueda/alejandra/issues/372
inherit (pkgs.haskell.lib)
# doJailbreak - remove package bounds from build-depends of a package
# https://github.com/kamadorueda/alejandra/issues/372
inherit
(pkgs.haskell.lib)
# doJailbreak - remove package bounds from build-depends of a package
doJailbreak
# dontCheck - skip tests
dontCheck
# override deps of a package
# see what can be overriden - https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/generic-builder.nix#L13
overrideCabal;
overrideCabal
;
}
6 changes: 6 additions & 0 deletions test/diff/inherit_from/in.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
inherit (builtins)
pathExists readFile isBool
isInt isFloat add sub lessThan
seq deepSeq genericClosure;
}
{ inherit ( c ) f h ; }
{ inherit ( c ) f h /*i*/; }
{ inherit ( c ) f /*g*/ h ; }
Expand Down
Loading

0 comments on commit 6ea9841

Please sign in to comment.