Skip to content

Commit

Permalink
Always use hardline in prettyItems
Browse files Browse the repository at this point in the history
The argument was never used for anything else
  • Loading branch information
infinisil committed May 14, 2024
1 parent 3bcb63c commit af0eb66
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ instance (Pretty a) => Pretty (Item a) where
pretty (CommentedItem trivia x) = pretty trivia <> group x

-- For lists, attribute sets and let bindings
prettyItems :: (Pretty a) => Doc -> Items a -> Doc
prettyItems :: (Pretty a) => Items a -> Doc
-- Special case: Preserve an empty line with no items
-- usually, trailing newlines after the last element are not preserved
prettyItems _ (Items [DetachedComments []]) = emptyline
prettyItems sep items = prettyItems' $ unItems items
prettyItems (Items [DetachedComments []]) = emptyline
prettyItems items = prettyItems' $ unItems items
where
prettyItems' :: (Pretty a) => [Item a] -> Doc
prettyItems' [] = mempty
prettyItems' [item] = pretty item
prettyItems' (item : xs) =
pretty item
<> case item of CommentedItem _ _ -> sep; DetachedComments _ -> emptyline
<> case item of CommentedItem _ _ -> hardline; DetachedComments _ -> emptyline
<> prettyItems' xs

instance Pretty [Trivium] where
Expand Down Expand Up @@ -170,7 +170,7 @@ prettySet _ (krec, Ann [] paropen Nothing, Items [], parclose@(Ann [] _ _)) =
prettySet wide (krec, Ann pre paropen post, binders, parclose) =
pretty (fmap (,hardspace) krec)
<> pretty (Ann pre paropen Nothing)
<> surroundWith sep (nest $ pretty post <> prettyItems hardline binders)
<> surroundWith sep (nest $ pretty post <> prettyItems binders)
<> pretty parclose
where
sep = if wide && not (null (unItems binders)) then hardline else line
Expand Down Expand Up @@ -207,7 +207,7 @@ prettyTerm (List (Ann leading paropen Nothing) (Items []) (Ann [] parclose trail
-- Always expand if len > 1
prettyTerm (List (Ann pre paropen post) items parclose) =
pretty (Ann pre paropen Nothing)
<> surroundWith line (nest $ pretty post <> prettyItems hardline items)
<> surroundWith line (nest $ pretty post <> prettyItems items)
<> pretty parclose
prettyTerm (Set krec paropen items parclose) = prettySet False (krec, paropen, items, parclose)
-- Parentheses
Expand Down Expand Up @@ -568,7 +568,7 @@ instance Pretty Expression where
(unItems binders)

letPart = group $ pretty let_ <> hardline <> letBody
letBody = nest $ prettyItems hardline (Items bindersWithoutComments)
letBody = nest $ prettyItems (Items bindersWithoutComments)
inPart =
group $
pretty (Ann [] in_ Nothing)
Expand Down

0 comments on commit af0eb66

Please sign in to comment.