diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 9f3f9e65..a9a078fd 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -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)) diff --git a/test/diff/idioms_lib_2/out.nix b/test/diff/idioms_lib_2/out.nix index 5c36db66..8b1e85f8 100644 --- a/test/diff/idioms_lib_2/out.nix +++ b/test/diff/idioms_lib_2/out.nix @@ -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. diff --git a/test/diff/inherit/out.nix b/test/diff/inherit/out.nix index 0717536b..31f53916 100644 --- a/test/diff/inherit/out.nix +++ b/test/diff/inherit/out.nix @@ -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 @@ -47,8 +56,11 @@ c # test d # test - e f + e + f - g h; + g + h + ; } ] diff --git a/test/diff/inherit_blank_trailing/out.nix b/test/diff/inherit_blank_trailing/out.nix index cac91152..7e8b2469 100644 --- a/test/diff/inherit_blank_trailing/out.nix +++ b/test/diff/inherit_blank_trailing/out.nix @@ -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 @@ -24,6 +28,6 @@ # comment 1 # comment 2 # comment 3 - ; + ; } ] diff --git a/test/diff/inherit_comment/out.nix b/test/diff/inherit_comment/out.nix index 83721a44..403a2353 100644 --- a/test/diff/inherit_comment/out.nix +++ b/test/diff/inherit_comment/out.nix @@ -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 + ; } diff --git a/test/diff/inherit_from/in.nix b/test/diff/inherit_from/in.nix index 691cf365..63ef95ab 100644 --- a/test/diff/inherit_from/in.nix +++ b/test/diff/inherit_from/in.nix @@ -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 ; } diff --git a/test/diff/inherit_from/out.nix b/test/diff/inherit_from/out.nix index 449e9f13..9b35aad2 100644 --- a/test/diff/inherit_from/out.nix +++ b/test/diff/inherit_from/out.nix @@ -1,414 +1,524 @@ [ + { + 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 + h # i + ; } { - inherit (c) + inherit + (c) f # g - h; + h + ; } { - inherit (c) + inherit + (c) f # g h # i - ; + ; } { - inherit (c) # e - f h; + inherit + (c) # e + f + h + ; } { - inherit (c) # e - f h # i - ; + inherit + (c) # e + f + h # i + ; } { - inherit (c) # e + inherit + (c) # e f # g - h; + h + ; } { - inherit (c) # e + inherit + (c) # e f # g h # i - ; + ; } { - inherit (c # d - ) - f h; + inherit + (c # d + ) + f + h + ; } { - inherit (c # d - ) - f h # i - ; + inherit + (c # d + ) + f + h # i + ; } { - inherit (c # d - ) + inherit + (c # d + ) f # g - h; + h + ; } { - inherit (c # d - ) + inherit + (c # d + ) f # g h # i - ; + ; } { - inherit (c # d - ) # e - f h; + inherit + (c # d + ) # e + f + h + ; } { - inherit (c # d - ) # e - f h # i - ; + inherit + (c # d + ) # e + f + h # i + ; } { - inherit (c # d - ) # e + inherit + (c # d + ) # e f # g - h; + h + ; } { - inherit (c # d - ) # e + inherit + (c # d + ) # e f # g h # i - ; + ; } { - inherit ( # b - c) - f h; + inherit + ( # b + c) + f + h + ; } { - inherit ( # b - c) - f h # i - ; + inherit + ( # b + c) + f + h # i + ; } { - inherit ( # b - c) + inherit + ( # b + c) f # g - h; + h + ; } { - inherit ( # b - c) + inherit + ( # b + c) f # g h # i - ; + ; } { - inherit ( # b - c) # e - f h; + inherit + ( # b + c) # e + f + h + ; } { - inherit ( # b - c) # e - f h # i - ; + inherit + ( # b + c) # e + f + h # i + ; } { - inherit ( # b - c) # e + inherit + ( # b + c) # e f # g - h; + h + ; } { - inherit ( # b - c) # e + inherit + ( # b + c) # e f # g h # i - ; + ; } { - inherit ( # b - c # d - ) - f h; + inherit + ( # b + c # d + ) + f + h + ; } { - inherit ( # b - c # d - ) - f h # i - ; + inherit + ( # b + c # d + ) + f + h # i + ; } { - inherit ( # b - c # d - ) + inherit + ( # b + c # d + ) f # g - h; + h + ; } { - inherit ( # b - c # d - ) + inherit + ( # b + c # d + ) f # g h # i - ; + ; } { - inherit ( # b - c # d - ) # e - f h; + inherit + ( # b + c # d + ) # e + f + h + ; } { - inherit ( # b - c # d - ) # e - f h # i - ; + inherit + ( # b + c # d + ) # e + f + h # i + ; } { - inherit ( # b - c # d - ) # e + inherit + ( # b + c # d + ) # e f # g - h; + h + ; } { - inherit ( # b - c # d - ) # e + inherit + ( # b + c # d + ) # e f # g h # i - ; + ; } { inherit # a - (c) - f h; + (c) + f + h + ; } { inherit # a - (c) - f h # i - ; + (c) + f + h # i + ; } { inherit # a - (c) + (c) f # g - h; + h + ; } { inherit # a - (c) + (c) f # g h # i - ; + ; } { inherit # a - (c) # e - f h; + (c) # e + f + h + ; } { inherit # a - (c) # e - f h # i - ; + (c) # e + f + h # i + ; } { inherit # a - (c) # e + (c) # e f # g - h; + h + ; } { inherit # a - (c) # e + (c) # e f # g h # i - ; + ; } { inherit # a - (c # d - ) - f h; + (c # d + ) + f + h + ; } { inherit # a - (c # d - ) - f h # i - ; + (c # d + ) + f + h # i + ; } { inherit # a - (c # d - ) + (c # d + ) f # g - h; + h + ; } { inherit # a - (c # d - ) + (c # d + ) f # g h # i - ; + ; } { inherit # a - (c # d - ) # e - f h; + (c # d + ) # e + f + h + ; } { inherit # a - (c # d - ) # e - f h # i - ; + (c # d + ) # e + f + h # i + ; } { inherit # a - (c # d - ) # e + (c # d + ) # e f # g - h; + h + ; } { inherit # a - (c # d - ) # e + (c # d + ) # e f # g h # i - ; + ; } { inherit # a - ( # b - c) - f h; + ( # b + c) + f + h + ; } { inherit # a - ( # b - c) - f h # i - ; + ( # b + c) + f + h # i + ; } { inherit # a - ( # b - c) + ( # b + c) f # g - h; + h + ; } { inherit # a - ( # b - c) + ( # b + c) f # g h # i - ; + ; } { inherit # a - ( # b - c) # e - f h; + ( # b + c) # e + f + h + ; } { inherit # a - ( # b - c) # e - f h # i - ; + ( # b + c) # e + f + h # i + ; } { inherit # a - ( # b - c) # e + ( # b + c) # e f # g - h; + h + ; } { inherit # a - ( # b - c) # e + ( # b + c) # e f # g h # i - ; + ; } { inherit # a - ( # b - c # d - ) - f h; + ( # b + c # d + ) + f + h + ; } { inherit # a - ( # b - c # d - ) - f h # i - ; + ( # b + c # d + ) + f + h # i + ; } { inherit # a - ( # b - c # d - ) + ( # b + c # d + ) f # g - h; + h + ; } { inherit # a - ( # b - c # d - ) + ( # b + c # d + ) f # g h # i - ; + ; } { inherit # a - ( # b - c # d - ) # e - f h; + ( # b + c # d + ) # e + f + h + ; } { inherit # a - ( # b - c # d - ) # e - f h # i - ; + ( # b + c # d + ) # e + f + h # i + ; } { inherit # a - ( # b - c # d - ) # e + ( # b + c # d + ) # e f # g - h; + h + ; } { inherit # a - ( # b - c # d - ) # e + ( # b + c # d + ) # e f # g h # i - ; + ; } ] diff --git a/test/diff/monsters_1/out.nix b/test/diff/monsters_1/out.nix index 02d7ee2b..f1b408a9 100644 --- a/test/diff/monsters_1/out.nix +++ b/test/diff/monsters_1/out.nix @@ -139,8 +139,9 @@ rec # foo inherit # foo - src; - # foo + src + ; + # foo name # foo = diff --git a/test/diff/monsters_4/out.nix b/test/diff/monsters_4/out.nix index 9360bc69..10c74252 100644 --- a/test/diff/monsters_4/out.nix +++ b/test/diff/monsters_4/out.nix @@ -69,7 +69,8 @@ rec # Foo rustPlatform.fetchCargoTarball # Foo { # Foo inherit # Foo - src; # Foo + src + ; # Foo name # Foo = # Foo "${pname}-${version}"; # Foo diff --git a/test/diff/monsters_5/out.nix b/test/diff/monsters_5/out.nix index af37fdaa..f580e883 100644 --- a/test/diff/monsters_5/out.nix +++ b/test/diff/monsters_5/out.nix @@ -18,23 +18,26 @@ let inherit - (config.boot) + (config.boot) - kernelPatches; + kernelPatches + ; inherit - (config.boot.kernel) + (config.boot.kernel) features - randstructSeed; + randstructSeed + ; inherit - (config.boot.kernelPackages) + (config.boot.kernelPackages) - kernel; + kernel + ; kernelModulesConf @@ -158,7 +161,8 @@ in { inherit - randstructSeed; + randstructSeed + ; kernelPatches