ormolu
ormolu copied to clipboard
Preserve blank lines between equations
I have code that looks like this — each equation is a handler for a different backend route:
instance Controller CardController where
action ShowCardAction { cardId } = do
accessDeniedUnless =<< userCanView @Card cardId
card <- fetch cardId
board <- fetch (get #boardId card)
cardUpdates <-
get #cardUpdates card
|> orderByDesc #createdAt
|> fetch
>>= filterM (userCanView @CardUpdate . get #id)
replySets <- forM cardUpdates \c ->
get #replies c
|> orderByAsc #createdAt
|> fetch
>>= filterM (userCanView @Reply . get #id)
>>= mapM fetchReplyV
render ShowView { cardUpdates = zip cardUpdates replySets, .. }
action EditCardAction { cardId } = do
accessDeniedUnless =<< userCanEdit @Card cardId
card <- fetch cardId
board <- fetch (get #boardId card)
render EditView { .. }
action UpdateCardAction { cardId } = do
accessDeniedUnless =<< userCanEdit @Card cardId
card <- fetch cardId
board <- fetch (get #boardId card)
card
|> buildCard
|> ifValid \case
Left card -> render EditView { .. }
Right card -> do
card <- card |> updateRecord
redirectTo ShowCardAction { .. }
-- ... more cases ...
"One equation per route" is the default style of the popular IHP framework.
Ormolu removes newlines between different equations and the code becomes harder to read. It would be nice if Ormolu didn't do that.
This seems similar to but dual to #635, where Ormolu is inserting objectionable blank lines and obscuring the grouping that way.
Perhaps it would be possible for ormolu to preserve groupings in all cases: don't insert blank lines where there were none, and don't remove blank lines where they existed.
I suppose this might create some implementation trickiness for reformatting records, where e.g.
data D = D
{ foo1 :: Int
, foo2 :: Int
, bar1 :: Int
, bar2 :: Int
} deriving (Blah)
would get reformatted as
data D = D
{ foo1 :: Int,
foo2 :: Int,
bar1 :: Int,
bar2 :: Int
}
deriving (Blah)
But since Ormolu can already correctly permute commas past comments in this case, hopefully similar logic would handle this.