diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index f4d39ed6..0bd91f5f 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -231,27 +231,37 @@ prettyTerm (Selection term selectors rest) = prettyTerm ( List paropen@Ann - { trailComment = Nothing + { sourceLine = openLine, + trailComment = Nothing } (Items []) parclose@Ann - { preTrivia = [] + { sourceLine = closeLine, + preTrivia = [] } ) = - pretty paropen <> hardspace <> pretty parclose + pretty paropen <> sep <> pretty parclose + where + -- If the brackets are on different lines, keep them like that + sep = if openLine /= closeLine then hardline else hardspace -- General list -- Always expand if len > 1 prettyTerm ( List paropen@Ann - { trailComment = post + { sourceLine = openLine, + trailComment = post } items - parclose + parclose@Ann + { sourceLine = closeLine + } ) = pretty (paropen{trailComment = Nothing}) - <> surroundWith line (nest $ pretty post <> prettyItems items) + <> surroundWith sur (nest $ pretty post <> prettyItems items) <> pretty parclose + where + sur = if openLine /= closeLine then hardline else line prettyTerm (Set krec paropen items parclose) = prettySet False (krec, paropen, items, parclose) -- Parentheses prettyTerm (Parenthesized paropen expr parclose@(Ann{preTrivia = closePre})) = diff --git a/test/diff/idioms_pkgs_3/out.nix b/test/diff/idioms_pkgs_3/out.nix index 066bc56e..13f30559 100644 --- a/test/diff/idioms_pkgs_3/out.nix +++ b/test/diff/idioms_pkgs_3/out.nix @@ -237,7 +237,9 @@ buildStdenv.mkDerivation ({ inherit src unpackPhase meta; - outputs = [ "out" ] ++ lib.optionals crashreporterSupport [ "symbols" ]; + outputs = [ + "out" + ] ++ lib.optionals crashreporterSupport [ "symbols" ]; # Add another configure-build-profiling run before the final configure phase if we build with pgo preConfigurePhases = lib.optionals pgoSupport [ diff --git a/test/diff/idioms_pkgs_4/out.nix b/test/diff/idioms_pkgs_4/out.nix index ecbb41bd..717216df 100644 --- a/test/diff/idioms_pkgs_4/out.nix +++ b/test/diff/idioms_pkgs_4/out.nix @@ -84,9 +84,13 @@ let ] ++ ( if system == "i686-cygwin" then - [ ../cygwin/rebase-i686.sh ] + [ + ../cygwin/rebase-i686.sh + ] else if system == "x86_64-cygwin" then - [ ../cygwin/rebase-x86_64.sh ] + [ + ../cygwin/rebase-x86_64.sh + ] else [ ] ); diff --git a/test/diff/lists/out.nix b/test/diff/lists/out.nix index fed594cd..6c168a80 100644 --- a/test/diff/lists/out.nix +++ b/test/diff/lists/out.nix @@ -46,7 +46,9 @@ ] [ 1 ] - [ 1 ] + [ + 1 + ] [ b diff --git a/test/diff/operation/out.nix b/test/diff/operation/out.nix index f094d0d2..4116160b 100644 --- a/test/diff/operation/out.nix +++ b/test/diff/operation/out.nix @@ -230,7 +230,9 @@ zip zlib ] - ++ [ (if (lib.versionAtLeast version "103") then nss_latest else nss_esr) ] + ++ [ + (if (lib.versionAtLeast version "103") then nss_latest else nss_esr) + ] ) # Indentation with parenthesized multiline function call