diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 3bfacee..49c4525 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -413,7 +413,7 @@ prettyApp indentFunction pre hasPost f a = <> pretty parclose where -- If the brackets are on different lines, keep them like that - sur = if sourceLine paropen /= sourceLine parclose then hardline else line + sur = if sourceLine paropen /= sourceLine parclose then hardline else if length (unItems items) > 0 then line else hardspace absorbInner expr = pretty expr -- Render the last argument of a function call diff --git a/test/diff/apply_with_lists/in.nix b/test/diff/apply_with_lists/in.nix index 86eebd2..df508ab 100644 --- a/test/diff/apply_with_lists/in.nix +++ b/test/diff/apply_with_lists/in.nix @@ -75,4 +75,7 @@ out = "20170512"; } ] null) + # https://github.com/NixOS/nixfmt/issues/268 regression test. [] and {} should be treated the same + (defaultNullOpts.mkNullable (with types; either str (listOf str)) [] "Some example long text that causes the line to be too long.") + (defaultNullOpts.mkNullable (with types; either str (listOf str)) {} "Some example long text that causes the line to be too long.") ] diff --git a/test/diff/apply_with_lists/out-pure.nix b/test/diff/apply_with_lists/out-pure.nix index 6c33da7..f13e62b 100644 --- a/test/diff/apply_with_lists/out-pure.nix +++ b/test/diff/apply_with_lists/out-pure.nix @@ -107,4 +107,11 @@ ] null ) + # https://github.com/NixOS/nixfmt/issues/268 regression test. [] and {} should be treated the same + (defaultNullOpts.mkNullable ( + with types; either str (listOf str) + ) [ ] "Some example long text that causes the line to be too long.") + (defaultNullOpts.mkNullable ( + with types; either str (listOf str) + ) { } "Some example long text that causes the line to be too long.") ] diff --git a/test/diff/apply_with_lists/out.nix b/test/diff/apply_with_lists/out.nix index bee7df4..fb2a655 100644 --- a/test/diff/apply_with_lists/out.nix +++ b/test/diff/apply_with_lists/out.nix @@ -117,4 +117,11 @@ ] null ) + # https://github.com/NixOS/nixfmt/issues/268 regression test. [] and {} should be treated the same + (defaultNullOpts.mkNullable ( + with types; either str (listOf str) + ) [ ] "Some example long text that causes the line to be too long.") + (defaultNullOpts.mkNullable ( + with types; either str (listOf str) + ) { } "Some example long text that causes the line to be too long.") ]