Skip to content

Commit

Permalink
Lists: Fix absorbtion rules
Browse files Browse the repository at this point in the history
For some reasons instead of one condition it was split into two conditions, which covered everything necessery minus one edge case
  • Loading branch information
piegamesde committed Jan 8, 2024
1 parent 35da232 commit a273e5a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@ isAbstractionWithAbsorbableTerm _ = False
isAbsorbable :: Term -> Bool
isAbsorbable (String (Ann _ parts@(_:_:_) _))
= not $ isSimpleString parts
-- Non-empty sets and lists
isAbsorbable (Set _ _ (Items (_:_)) _) = True
isAbsorbable (List (Ann [] _ Nothing) (Items [CommentedItem [] _]) _) = True
isAbsorbable (List _ (Items (_:_)) _) = True
isAbsorbable (Parenthesized (Ann [] _ Nothing) (Term t) _) = isAbsorbable t
isAbsorbable (List _ (Items (_:_:_)) _) = True
isAbsorbable _ = False

absorb :: Doc -> Doc -> Maybe Int -> Expression -> Doc
Expand Down
10 changes: 4 additions & 6 deletions test/diff/idioms_nixos_1/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,10 @@ in
]
);

boot.initrd.kernelModules =
optionals config.boot.initrd.includeDefaultModules
[
# For LVM.
"dm_mod"
];
boot.initrd.kernelModules = optionals config.boot.initrd.includeDefaultModules [
# For LVM.
"dm_mod"
];
})

(mkIf (!config.boot.isContainer) {
Expand Down
14 changes: 14 additions & 0 deletions test/diff/lists/in.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
foo = "bar";
foo2 = "barbar";
} ]
{ # List in attrset with comment

imports0 = [];

imports2 = [
# ./disko.nix
./hardware-configuration.nix
];
imports3 = [
# comment
./disko.nix
./hardware-configuration.nix
];
}
[ (if foo then
bar #multiline too
else
Expand Down
15 changes: 15 additions & 0 deletions test/diff/lists/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
foo2 = "barbar";
}
]
{
# List in attrset with comment

imports0 = [ ];

imports2 = [
# ./disko.nix
./hardware-configuration.nix
];
imports3 = [
# comment
./disko.nix
./hardware-configuration.nix
];
}
[
(
if foo then
Expand Down

0 comments on commit a273e5a

Please sign in to comment.