From b19ea26a7de2e4f46176990ebbe90528e5d79af1 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 26 Nov 2024 18:16:40 +0100 Subject: [PATCH] Remove single-line list length restriction This restriction doesn't appear to be necessary anymore, and is the last remaining cause for `mkRenamedOptionModule`'s being formatted poorly. --- src/Nixfmt/Pretty.hs | 2 +- test/diff/apply_with_lists/out-pure.nix | 25 ++----------------------- test/diff/apply_with_lists/out.nix | 17 +---------------- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index ae3e305..f7e3a82 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -398,7 +398,7 @@ prettyApp indentFunction pre hasPost f a = -- If lists have only simple items, try to render them single-line instead of expanding -- This is just a copy of the list rendering code, but with `sepBy line` instead of `sepBy hardline` absorbInner (Term (List paropen@Ann{trailComment = post'} items parclose)) - | length (unItems items) <= 4 && all (isSimple . Term) items = + | all (isSimple . Term) items = pretty (paropen{trailComment = Nothing}) <> surroundWith sur (nest $ pretty post' <> sepBy line (unItems items)) <> pretty parclose diff --git a/test/diff/apply_with_lists/out-pure.nix b/test/diff/apply_with_lists/out-pure.nix index edf22e6..6c33da7 100644 --- a/test/diff/apply_with_lists/out-pure.nix +++ b/test/diff/apply_with_lists/out-pure.nix @@ -18,22 +18,7 @@ [ ''\"'' "\\\\" ] name ) - (replaceStrings - [ - "@" - ":" - "\\" - "[" - "]" - ] - [ - "-" - "-" - "-" - "" - "" - ] - ) + (replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ]) (lists.removePrefix [ 1 @@ -67,13 +52,7 @@ [ "hardware" "graphics" ] ) (mkRenamedOptionModule - [ - "services" - "xserver" - "displayManager" - "sddm" - "enable" - ] + [ "services" "xserver" "displayManager" "sddm" "enable" ] [ "services" "displayManager" "sddm" "enable" ] ) (map ( diff --git a/test/diff/apply_with_lists/out.nix b/test/diff/apply_with_lists/out.nix index 580e2b6..bee7df4 100644 --- a/test/diff/apply_with_lists/out.nix +++ b/test/diff/apply_with_lists/out.nix @@ -18,22 +18,7 @@ [ ''\"'' "\\\\" ] name ) - (replaceStrings - [ - "@" - ":" - "\\" - "[" - "]" - ] - [ - "-" - "-" - "-" - "" - "" - ] - ) + (replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ]) (lists.removePrefix [ 1