diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 439d1887..9b4c8e65 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -113,10 +113,17 @@ prettyTerm (List (Ann paropen Nothing []) [] parclose) = pretty paropen <> hardspace <> pretty parclose -- Singleton list +-- Expand unless absorbable term or single line prettyTerm (List (Ann paropen Nothing []) [item] parclose) - = pretty paropen <> hardspace <> pretty item <> hardspace <> pretty parclose + = pretty paropen + <> (if isAbsorbable item then + (hardspace <> pretty item <> hardspace) + else + (nest 2 (line <> pretty item <> line)) + ) <> pretty parclose -- General list +-- Always expand prettyTerm (List (Ann paropen trailing leading) items parclose) = base $ pretty paropen <> pretty trailing <> hardline <> nest 2 (pretty leading <> sepBy hardline (map group items)) <> hardline diff --git a/test/diff/idioms_pkgs_3/out.nix b/test/diff/idioms_pkgs_3/out.nix index d48009d0..255c0a11 100644 --- a/test/diff/idioms_pkgs_3/out.nix +++ b/test/diff/idioms_pkgs_3/out.nix @@ -253,13 +253,15 @@ buildStdenv.mkDerivation ({ "profilingPhase" ]; - patches = lib.optionals (lib.versionOlder version "102.6.0") [ (fetchpatch { - # https://bugzilla.mozilla.org/show_bug.cgi?id=1773259 - name = "rust-cbindgen-0.24.2-compat.patch"; - url = - "https://raw.githubusercontent.com/canonical/firefox-snap/5622734942524846fb0eb7108918c8cd8557fde3/patches/fix-ftbfs-newer-cbindgen.patch"; - hash = "sha256-+wNZhkDB3HSknPRD4N6cQXY7zMT/DzNXx29jQH0Gb1o="; - }) ] ++ lib.optional (lib.versionOlder version "111") + patches = lib.optionals (lib.versionOlder version "102.6.0") [ + (fetchpatch { + # https://bugzilla.mozilla.org/show_bug.cgi?id=1773259 + name = "rust-cbindgen-0.24.2-compat.patch"; + url = + "https://raw.githubusercontent.com/canonical/firefox-snap/5622734942524846fb0eb7108918c8cd8557fde3/patches/fix-ftbfs-newer-cbindgen.patch"; + hash = "sha256-+wNZhkDB3HSknPRD4N6cQXY7zMT/DzNXx29jQH0Gb1o="; + }) + ] ++ lib.optional (lib.versionOlder version "111") ./env_var_for_system_dir-ff86.patch ++ lib.optional (lib.versionAtLeast version "111") ./env_var_for_system_dir-ff111.patch @@ -471,11 +473,12 @@ buildStdenv.mkDerivation ({ xorg.xorgproto zip zlib - ] ++ [ (if (lib.versionAtLeast version "103") then - nss_latest - else - nss_esr) ] ++ lib.optional alsaSupport alsa-lib - ++ lib.optional jackSupport libjack2 + ] ++ [ + (if (lib.versionAtLeast version "103") then + nss_latest + else + nss_esr) + ] ++ lib.optional alsaSupport alsa-lib ++ lib.optional jackSupport libjack2 ++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed ++ lib.optional sndioSupport sndio ++ lib.optional gssSupport libkrb5 ++ lib.optionals waylandSupport [ diff --git a/test/diff/lists/in.nix b/test/diff/lists/in.nix index bf96dfb4..6798858e 100644 --- a/test/diff/lists/in.nix +++ b/test/diff/lists/in.nix @@ -1,4 +1,14 @@ [ + [ { + # multiline + foo = "bar"; + foo2 = "barbar"; + } ] + [ (if foo then + bar #multiline too + else + baz + )] [ 1 ] [ 1 @@ -43,4 +53,9 @@ ] + + [ [ multi line ] ] + [ [ [ singleton ] ] ] + [ [ [ { } ] ] ] + [ [ [ { } multiline ] ] ] ] diff --git a/test/diff/lists/out.nix b/test/diff/lists/out.nix index 83a2a53f..7ddc70a1 100644 --- a/test/diff/lists/out.nix +++ b/test/diff/lists/out.nix @@ -1,4 +1,15 @@ [ + [ { + # multiline + foo = "bar"; + foo2 = "barbar"; + } ] + [ + (if foo then + bar # multiline too + else + baz) + ] [ 1 ] [ 1 ] @@ -57,4 +68,14 @@ ] + [ [ + multi + line + ] ] + [ [ [ singleton ] ] ] + [ [ [ { } ] ] ] + [ [ [ + { } + multiline + ] ] ] ]