1- {-# LANGUAGE FlexibleInstances, OverloadedStrings, LambdaCase #-}
1+ {-# LANGUAGE FlexibleInstances, OverloadedStrings #-}
22
33module Nixfmt.Predoc
44 ( text
@@ -151,7 +151,7 @@ trailing t = [Text 0 0 Trailing t]
151151-- Must not contain non-hard whitespace (e.g. line, softline' etc.) at the start of the end.
152152-- Use group' for that instead if you are sure of what you are doing.
153153group :: HasCallStack => Pretty a => a -> Doc
154- group x = pure . ( Group RegularG ) $
154+ group x = pure . Group RegularG $
155155 if p /= [] && (isSoftSpacing (head p) || isSoftSpacing (last p)) then
156156 error $ " group should not start or end with whitespace, use `group'` if you are sure; " <> show p
157157 else
@@ -166,7 +166,7 @@ group x = pure . (Group RegularG) $
166166--
167167-- Also allows to create priority groups (see Node Group documentation)
168168group' :: Pretty a => GroupAnn -> a -> Doc
169- group' ann = pure . ( Group ann) . pretty
169+ group' ann = pure . Group ann . pretty
170170
171171-- | @nest doc@ declarse @doc@ to have a higher nesting depth
172172-- than before. Not all nestings actually result in indentation changes,
@@ -276,10 +276,10 @@ spanEnd p = fmap reverse . span p . reverse
276276unexpandSpacing' :: Maybe Int -> Doc -> Maybe Doc
277277unexpandSpacing' (Just n) _ | n < 0 = Nothing
278278unexpandSpacing' _ [] = Just []
279- unexpandSpacing' n (txt@ (Text _ _ _ t): xs) = (txt : ) <$> unexpandSpacing' (n <&> ( subtract $ textWidth t)) xs
280- unexpandSpacing' n (Spacing Hardspace : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> ( subtract 1 ) ) xs
281- unexpandSpacing' n (Spacing Space : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> ( subtract 1 ) ) xs
282- unexpandSpacing' n (Spacing Softspace : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> ( subtract 1 ) ) xs
279+ unexpandSpacing' n (txt@ (Text _ _ _ t): xs) = (txt : ) <$> unexpandSpacing' (n <&> subtract ( textWidth t)) xs
280+ unexpandSpacing' n (Spacing Hardspace : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> subtract 1 ) xs
281+ unexpandSpacing' n (Spacing Space : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> subtract 1 ) xs
282+ unexpandSpacing' n (Spacing Softspace : xs) = (Spacing Hardspace : ) <$> unexpandSpacing' (n <&> subtract 1 ) xs
283283unexpandSpacing' n (Spacing Break : xs) = unexpandSpacing' n xs
284284unexpandSpacing' n (Spacing Softbreak : xs) = unexpandSpacing' n xs
285285unexpandSpacing' _ (Spacing _: _) = Nothing
@@ -316,7 +316,7 @@ fixup (a@(Spacing _) : Group ann xs : ys) =
316316 -- For the leading side, also move out comments out of groups, they are kinda the same thing
317317 -- (We could move out trailing comments too but it would make no difference)
318318 (pre, rest) = span (\ x -> isHardSpacing x || isComment x) $ fixup xs
319- (post, body) = ( second $ simplifyGroup ann) $ spanEnd isHardSpacing rest
319+ (post, body) = second ( simplifyGroup ann) $ spanEnd isHardSpacing rest
320320 in if null body then
321321 -- Dissolve empty group
322322 fixup $ (a : pre) ++ post ++ ys
@@ -326,7 +326,7 @@ fixup (a@(Spacing _) : Group ann xs : ys) =
326326fixup (Group ann xs : ys) =
327327 let
328328 (pre, rest) = span (\ x -> isHardSpacing x || isComment x) $ fixup xs
329- (post, body) = ( second $ simplifyGroup ann) $ spanEnd isHardSpacing rest
329+ (post, body) = second ( simplifyGroup ann) $ spanEnd isHardSpacing rest
330330 in if null body then
331331 fixup $ pre ++ post ++ ys
332332 else
@@ -380,7 +380,7 @@ priorityGroups = explode . mergeSegments . segments
380380 | prio = [([] , x, [] )]
381381 | otherwise = []
382382 explode ((prio, x): xs)
383- | prio = ([] , x, concatMap ( snd ) xs) : ( map (\ (a, b, c) -> (x<> a, b, c)) $ explode xs)
383+ | prio = ([] , x, concatMap snd xs) : map (\ (a, b, c) -> (x<> a, b, c)) ( explode xs)
384384 | otherwise = map (\ (a, b, c) -> (x<> a, b, c)) (explode xs)
385385
386386-- | To support i18n, this function needs to be patched.
@@ -434,7 +434,7 @@ firstLineFits targetWidth maxWidth docs = go maxWidth docs
434434 where go c _ | c < 0 = False
435435 go c [] = maxWidth - c <= targetWidth
436436 go c (Text _ _ RegularT t : xs) = go (c - textWidth t) xs
437- go c (Text _ _ _ _ : xs) = go c xs
437+ go c (Text {} : xs) = go c xs
438438 -- This case is impossible in the input thanks to fixup, but may happen
439439 -- due to our recursion on groups below
440440 go c (Spacing a : Spacing b : xs) = go c $ Spacing (mergeSpacings a b) : xs
@@ -534,7 +534,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
534534 -- [ # comment
535535 -- 1
536536 -- ]
537- Text _ _ TrailingComment t | cc == 2 && ( fst $ nextIndent xs) > lineNL -> putText' [" " , t]
537+ Text _ _ TrailingComment t | cc == 2 && fst ( nextIndent xs) > lineNL -> putText' [" " , t]
538538 where lineNL = snd $ NonEmpty. head indents
539539 Text nl off _ t -> putText nl off t
540540
@@ -572,7 +572,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
572572 -- Ignore transparent groups as their priority children have already been handled up in the parent (and failed)
573573 <|> (if ann /= Transparent then
574574 -- Each priority group will be handled individually, and the priority groups are tried in reverse order
575- asum $ map (flip goPriorityGroup xs) $ reverse $ priorityGroups ys
575+ asum $ map (` goPriorityGroup` xs) $ reverse $ priorityGroups ys
576576 else
577577 empty
578578 )
@@ -593,7 +593,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
593593 -- Try to render post onto one line
594594 postRendered <- goGroup post rest
595595 -- If none of these failed, put together and return
596- return $ (preRendered ++ prioRendered ++ postRendered)
596+ return (preRendered ++ prioRendered ++ postRendered)
597597
598598 -- Try to fit the group onto a single line, while accounting for the fact that the first
599599 -- bits of rest must fit as well (until the first possibility for a line break within rest).
@@ -610,7 +610,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
610610 -- therefore drop any leading whitespace within the group to avoid duplicate newlines
611611 grp' = case head grp of
612612 Spacing _ -> tail grp
613- Group ann ((Spacing _) : inner) -> ( Group ann inner) : tail grp
613+ Group ann ((Spacing _) : inner) -> Group ann inner : tail grp
614614 _ -> grp
615615 (nl, off) = nextIndent grp'
616616
0 commit comments