diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 24a8e7e9..614d0dda 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -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 diff --git a/test/diff/idioms_nixos_1/out.nix b/test/diff/idioms_nixos_1/out.nix index 2d26acba..22225f2f 100644 --- a/test/diff/idioms_nixos_1/out.nix +++ b/test/diff/idioms_nixos_1/out.nix @@ -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) { diff --git a/test/diff/lists/in.nix b/test/diff/lists/in.nix index 6798858e..56352bc1 100644 --- a/test/diff/lists/in.nix +++ b/test/diff/lists/in.nix @@ -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 diff --git a/test/diff/lists/out.nix b/test/diff/lists/out.nix index 75ffcf4d..8cbd273a 100644 --- a/test/diff/lists/out.nix +++ b/test/diff/lists/out.nix @@ -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