Skip to content

Commit

Permalink
Tweak absorbtion rules on bindings with Operation RHS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
piegamesde committed Dec 2, 2024
1 parent 1d7936e commit d58725d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion test/diff/idioms_nixos_2/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit d58725d

Please sign in to comment.