Skip to content

Commit

Permalink
Improve consistency when formatting certain applicands
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen authored and mrkkrp committed Apr 12, 2023
1 parent ee75df1 commit 2ee0dab
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 90 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased

* Consistently format `do` blocks/`case`s/`MultiWayIf`s with 4 spaces if and
only if they occur as the applicand. [Issue
1002](https://github.com/tweag/ormolu/issues/1002) and [issue
730](https://github.com/tweag/ormolu/issues/730).

## Ormolu 0.6.0.1

* Fix false positives in AST diffing related to `UnicodeSyntax`. [PR
Expand Down
22 changes: 11 additions & 11 deletions data/examples/declaration/value/function/application-1-out.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
main =
do
x
y
z
x
y
z

main =
case foo of
x -> a
foo
a
b
x -> a
foo
a
b

main =
do
if x then y else z
foo
a
b
if x then y else z
foo
a
b
12 changes: 6 additions & 6 deletions data/examples/declaration/value/function/application-2-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ foo = do

foo = do
do
(+ 1)
2
(+ 1)
2

foo = do
case () of () -> (+ 1)
2

foo = do
case () of
() -> (+ 1)
2
() -> (+ 1)
2

foo = do
\case 2 -> 3
2

foo = do
\case
2 -> 3
2
2 -> 3
2
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ g x = proc (y, z) ->
LT -> \a -> returnA -< x + a
EQ -> \b -> returnA -< y + z + b
GT -> \c -> returnA -< z + x
) 1
)
1
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ bazbar f = proc a -> do
f
-<
a

foo =
proc x ->
do
returnA -< x
1

foo a =
proc x ->
case Left x of
Left x -> returnA -< x
a
10 changes: 10 additions & 0 deletions data/examples/declaration/value/function/arrow/proc-do-simple1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ bazbar f = proc a ->
-<
a

foo =
proc x -> do
returnA -< x
1

foo a =
proc x ->
case Left x of
Left x -> returnA -< x
a
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ foo1 x = proc (y, z) -> do
(|
bar
(bindA -< y)
|) z
|)
z
8 changes: 4 additions & 4 deletions data/examples/declaration/value/function/multi-way-if-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ foo x = if | x == 5 -> 5

bar x y =
if
| x > y -> x
| x < y ->
y
| otherwise -> x
| x > y -> x
| x < y ->
y
| otherwise -> x

baz =
if
Expand Down
6 changes: 3 additions & 3 deletions src/Ormolu/Fixity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,6 @@ mergeFixityMaps popularityMap threshold packageMaps =
comp (fMax, maxs) x =
let fX = f x
in if
| fMax < fX -> (fX, x :| [])
| fMax == fX -> (fMax, NE.cons x maxs)
| otherwise -> (fMax, maxs)
| fMax < fX -> (fX, x :| [])
| fMax == fX -> (fMax, NE.cons x maxs)
| otherwise -> (fMax, maxs)
1 change: 0 additions & 1 deletion src/Ormolu/Printer/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Ormolu.Printer.Combinators
newline,
inci,
inciIf,
inciHalf,
askSourceType,
askFixityOverrides,
askFixityMap,
Expand Down
6 changes: 0 additions & 6 deletions src/Ormolu/Printer/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module Ormolu.Printer.Internal
askFixityOverrides,
askFixityMap,
inci,
inciHalf,
sitcc,
Layout (..),
enterLayout,
Expand Down Expand Up @@ -411,11 +410,6 @@ inciBy step (R m) = R (local modRC m)
inci :: R () -> R ()
inci = inciBy indentStep

-- | In rare cases, we have to indent by a positive amount smaller
-- than 'indentStep'.
inciHalf :: R () -> R ()
inciHalf = inciBy $ (indentStep `div` 2) `max` 1

-- | Set indentation level for the inner computation equal to current
-- column. This makes sure that the entire inner block is uniformly
-- \"shifted\" to the right.
Expand Down
5 changes: 3 additions & 2 deletions src/Ormolu/Printer/Meat/Declaration/OpTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import GHC.Types.SrcLoc
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common (p_rdrName)
import Ormolu.Printer.Meat.Declaration.Value
( cmdTopPlacement,
( IsApplicand (..),
cmdTopPlacement,
exprPlacement,
p_hsCmdTop,
p_hsExpr,
Expand Down Expand Up @@ -91,7 +92,7 @@ p_exprOpTree ::
-- operator fixity
OpTree (LHsExpr GhcPs) (OpInfo (LHsExpr GhcPs)) ->
R ()
p_exprOpTree s (OpNode x) = located x (p_hsExpr' s)
p_exprOpTree s (OpNode x) = located x (p_hsExpr' NotApplicand s)
p_exprOpTree s t@(OpBranches exprs ops) = do
let firstExpr = head exprs
otherExprs = tail exprs
Expand Down
Loading

0 comments on commit 2ee0dab

Please sign in to comment.