Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Nixfmt/Predoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ trailing t = [Text 0 0 Trailing t]
group :: (HasCallStack) => (Pretty a) => a -> Doc
group x =
pure . Group RegularG $
if p /= [] && (isSoftSpacing (head p) || isSoftSpacing (last p))
then error $ "group should not start or end with whitespace, use `group'` if you are sure; " <> show p
else p
case p of
(headP : _)
| isSoftSpacing headP || isSoftSpacing (last p) ->
error $ "group should not start or end with whitespace, use `group'` if you are sure; " <> show p
_ -> p
where
p = pretty x

Expand Down Expand Up @@ -631,9 +633,9 @@ layoutGreedy tw iw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0
then
let -- We know that the last printed character was a line break (cc == 0),
-- therefore drop any leading whitespace within the group to avoid duplicate newlines
grp' = case head grp of
Spacing _ -> tail grp
Group ann ((Spacing _) : inner) -> Group ann inner : tail grp
grp' = case grp of
Spacing _ : tl -> tl
Group ann ((Spacing _) : inner) : tl -> Group ann inner : tl
_ -> grp
(nl, off) = nextIndent grp'

Expand Down
4 changes: 2 additions & 2 deletions src/Nixfmt/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ instance LanguageElement Term where

walkSubprograms = \case
-- Map each item to a singleton list, then handle that
(List _ items _) | Prelude.length (unItems items) == 1 -> case Prelude.head (unItems items) of
(List _ (Items [singleItem]) _) -> case singleItem of
(Item item) -> [Term item]
(Comments _) -> []
(List open items close) ->
Expand All @@ -381,7 +381,7 @@ instance LanguageElement Term where
[Term (List (stripTrivia open) (Items [Item item]) (stripTrivia close))]
Comments c ->
[Term (List (stripTrivia open) (Items [Comments c]) (stripTrivia close))]
(Set _ _ items _) | Prelude.length (unItems items) == 1 -> case Prelude.head (unItems items) of
(Set _ _ (Items [singleItem]) _) -> case singleItem of
(Item (Inherit _ from sels _)) ->
(Term <$> maybeToList from) ++ concatMap walkSubprograms sels
(Item (Assignment sels _ expr _)) ->
Expand Down