Skip to content

Commit

Permalink
Expand singleton lists with a multiline item
Browse files Browse the repository at this point in the history
Except when that item is another list or attribute set
  • Loading branch information
piegamesde committed May 7, 2023
1 parent dafec15 commit de7bd6d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions test/diff/idioms_pkgs_3/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [
Expand Down
15 changes: 15 additions & 0 deletions test/diff/lists/in.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
[ {
# multiline
foo = "bar";
foo2 = "barbar";
} ]
[ (if foo then
bar #multiline too
else
baz
)]
[ 1 ]

[ 1
Expand Down Expand Up @@ -43,4 +53,9 @@

]


[ [ multi line ] ]
[ [ [ singleton ] ] ]
[ [ [ { } ] ] ]
[ [ [ { } multiline ] ] ]
]
21 changes: 21 additions & 0 deletions test/diff/lists/out.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[
[ {
# multiline
foo = "bar";
foo2 = "barbar";
} ]
[
(if foo then
bar # multiline too
else
baz)
]
[ 1 ]

[ 1 ]
Expand Down Expand Up @@ -57,4 +68,14 @@

]

[ [
multi
line
] ]
[ [ [ singleton ] ] ]
[ [ [ { } ] ] ]
[ [ [
{ }
multiline
] ] ]
]

0 comments on commit de7bd6d

Please sign in to comment.