diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index d4a2497c..c6ff7c96 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -129,8 +129,11 @@ instance Pretty Binder where pretty inherit <> ( if null ids then pretty semicolon - else line <> nest (sepBy (if length ids < 4 then line else hardline) ids <> line' <> pretty semicolon) + else line <> nest (sepBy sep ids <> line' <> pretty semicolon) ) + where + -- Only allow a single line if it's already on a single line and has few enough elements + sep = if sourceLine inherit == sourceLine semicolon && length ids < 4 then line else hardline -- `inherit (foo) bar` statement pretty (Inherit inherit (Just source) ids semicolon) = group $ @@ -141,10 +144,13 @@ instance Pretty Binder where then pretty semicolon else line - <> sepBy (if length ids < 4 then line else hardline) ids + <> sepBy sep ids <> line' <> pretty semicolon ) + where + -- Only allow a single line if it's already on a single line and has few enough elements + sep = if sourceLine inherit == sourceLine semicolon && length ids < 4 then line else hardline -- `foo = bar` pretty (Assignment selectors assign expr semicolon) = group $