From d58725d160c4a3a696a686816ac9c17c30a63365 Mon Sep 17 00:00:00 2001 From: piegames Date: Mon, 2 Dec 2024 21:41:56 +0100 Subject: [PATCH] Tweak absorbtion rules on bindings with Operation RHS Fixes #198. This is a hotfix that should exclude the most common ugly case people might run into, if this comes up again we should more thoroughly rethink the rules for this case. --- src/Nixfmt/Pretty.hs | 6 +++++- test/diff/idioms_nixos_2/out-pure.nix | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 49c4525..9d549cc 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -600,7 +600,11 @@ absorbRHS expr = case expr of -- Special case `//` and `++` operations to be more compact in some cases -- Case 1: two arguments, LHS is absorbable term, RHS fits onto the last line (Operation (Term t) (LoneAnn op) b) - | isAbsorbable t && isUpdateOrConcat op -> + | isAbsorbable t + && isUpdateOrConcat op + -- Exclude further operations on the RHS + -- Hotfix for https://github.com/NixOS/nixfmt/issues/198 + && case b of (Operation{}) -> False; _ -> True -> group' RegularG $ line <> group' Priority (prettyTermWide t) <> line <> pretty op <> hardspace <> pretty b -- Case 2a: LHS fits onto first line, RHS is an absorbable term (Operation l (LoneAnn op) (Term t)) diff --git a/test/diff/idioms_nixos_2/out-pure.nix b/test/diff/idioms_nixos_2/out-pure.nix index 98e94de..d0403c7 100644 --- a/test/diff/idioms_nixos_2/out-pure.nix +++ b/test/diff/idioms_nixos_2/out-pure.nix @@ -51,7 +51,8 @@ let post_max_size = cfg.maxUploadSize; memory_limit = cfg.maxUploadSize; } - // cfg.phpOptions // optionalAttrs cfg.caching.apcu { "apc.enable_cli" = "1"; }; + // cfg.phpOptions + // optionalAttrs cfg.caching.apcu { "apc.enable_cli" = "1"; }; occ = pkgs.writeScriptBin "nextcloud-occ" '' #! ${pkgs.runtimeShell}