diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 929209d8..84bfc340 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -315,7 +315,9 @@ instance Pretty Parameter where pretty (IDParameter i) = pretty i -- {}: pretty (SetParameter bopen [] bclose) = - group $ pretty (moveTrailingCommentUp bopen) <> hardspace <> pretty bclose + group $ pretty (moveTrailingCommentUp bopen) <> sep <> pretty bclose + where + sep = if sourceLine bopen /= sourceLine bclose then hardline else hardspace -- { stuff }: pretty (SetParameter bopen attrs bclose) = group $ @@ -332,14 +334,17 @@ instance Pretty Parameter where [pretty (ParamAttr name maybeDefault Nothing) <> trailing ","] handleTrailingComma (x : xs) = pretty x : handleTrailingComma xs - sep = case attrs of - [ParamEllipsis _] -> line - -- Attributes must be without default - [ParamAttr _ Nothing _] -> line - [ParamAttr _ Nothing _, ParamEllipsis _] -> line - [ParamAttr _ Nothing _, ParamAttr _ Nothing _] -> line - [ParamAttr _ Nothing _, ParamAttr _ Nothing _, ParamEllipsis _] -> line - _ -> hardline + sep = + if sourceLine bopen /= sourceLine bclose + then hardline + else case attrs of + [ParamEllipsis _] -> line + -- Attributes must be without default + [ParamAttr _ Nothing _] -> line + [ParamAttr _ Nothing _, ParamEllipsis _] -> line + [ParamAttr _ Nothing _, ParamAttr _ Nothing _] -> line + [ParamAttr _ Nothing _, ParamAttr _ Nothing _, ParamEllipsis _] -> line + _ -> hardline pretty (ContextParameter param1 at param2) = pretty param1 <> pretty at <> pretty param2 diff --git a/test/diff/idioms_lib_3/out.nix b/test/diff/idioms_lib_3/out.nix index 74813d4f..4a1b2843 100644 --- a/test/diff/idioms_lib_3/out.nix +++ b/test/diff/idioms_lib_3/out.nix @@ -12,7 +12,9 @@ # # Tests can be found in ./tests/misc.nix # Documentation in the manual, #sec-generators -{ lib }: +{ + lib, +}: with (lib).trivial; let libStr = lib.strings; @@ -29,7 +31,8 @@ rec { # The builtin `toString` function has some strange defaults, # suitable for bash scripts but not much else. mkValueStringDefault = - { }: + { + }: v: with builtins; let @@ -203,7 +206,10 @@ rec { # allow lists as values for duplicate keys listsAsDuplicateKeys ? false, }: - { globalSection, sections }: + { + globalSection, + sections, + }: ( if globalSection == { } then "" @@ -279,7 +285,10 @@ rec { # Generates JSON from an arbitrary (non-function) value. # For more information see the documentation of the builtin. - toJSON = { }: builtins.toJSON; + toJSON = + { + }: + builtins.toJSON; # YAML has been a strict superset of JSON since 1.2, so we # use toJSON. Before it only had a few differences referring @@ -465,7 +474,8 @@ rec { # PLIST handling toPlist = - { }: + { + }: v: let isFloat = builtins.isFloat or (x: false); @@ -546,7 +556,8 @@ rec { # Note that integers are translated to Integer and never # the Natural type. toDhall = - { }@args: + { + }@args: v: with builtins; let diff --git a/test/diff/key_value/out.nix b/test/diff/key_value/out.nix index 1d93de5b..0ced3361 100644 --- a/test/diff/key_value/out.nix +++ b/test/diff/key_value/out.nix @@ -56,7 +56,12 @@ rec { c = 2; }; n = pkgs: { }; - o = { pkgs, ... }: { }; + o = + { + pkgs, + ... + }: + { }; a # b diff --git a/test/diff/lambda/in.nix b/test/diff/lambda/in.nix index 12d30655..0f7f7a5c 100644 --- a/test/diff/lambda/in.nix +++ b/test/diff/lambda/in.nix @@ -2,6 +2,13 @@ let inherit lib; in [ + ({}: null) + ({ + }: null) + ({ + + }: null) + ( { lib, }: let diff --git a/test/diff/lambda/out.nix b/test/diff/lambda/out.nix index 64078167..16eb44de 100644 --- a/test/diff/lambda/out.nix +++ b/test/diff/lambda/out.nix @@ -2,6 +2,19 @@ let inherit lib; in [ + ({ }: null) + ( + { + }: + null + ) + ( + { + + }: + null + ) + ( { lib }: let @@ -81,7 +94,10 @@ in ( a: - { b, ... }: + { + b, + ... + }: c: { # Stuff } @@ -89,7 +105,11 @@ in ( a: - { b, c, ... }: + { + b, + c, + ... + }: d: { # Stuff }