Skip to content

Commit

Permalink
Fix regression with empty list arguments in function application
Browse files Browse the repository at this point in the history
Fixes #268
  • Loading branch information
piegamesde committed Dec 2, 2024
1 parent 3587552 commit 1d7936e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/diff/apply_with_lists/in.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
]
7 changes: 7 additions & 0 deletions test/diff/apply_with_lists/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
]
7 changes: 7 additions & 0 deletions test/diff/apply_with_lists/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
]

0 comments on commit 1d7936e

Please sign in to comment.