diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index fd8ad7ec..5f4f9663 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -205,13 +205,19 @@ prettyTerm (Selection term selectors rest) = -- Empty list prettyTerm (List paropen@Ann{trailComment = Nothing} (Items []) parclose@Ann{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 sourceLine paropen /= sourceLine parclose then hardline else hardspace -- General list -- Always expand if len > 1 prettyTerm (List paropen@Ann{trailComment = post} items parclose) = pretty (paropen{trailComment = Nothing}) - <> surroundWith line (nest $ pretty post <> prettyItems items) + <> surroundWith sur (nest $ pretty post <> prettyItems items) <> pretty parclose + where + -- If the brackets are on different lines, keep them like that + sur = if sourceLine paropen /= sourceLine parclose 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