Skip to content

Commit

Permalink
Remove unnecessary indentation from list comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 authored and mrkkrp committed Jun 12, 2024
1 parent 27ec3fb commit 5c816de
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 122 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Don't require a trailing newline in `.ormolu` files. [Issue
1122](https://github.com/tweag/ormolu/issues/1122).

* Remove unnecessary indentation from list comprehensions. [Issue
966](https://github.com/tweag/ormolu/issues/966).

## Ormolu 0.7.5.0

* Switched to `ghc-lib-parser-9.10`, with the following new syntactic features/behaviors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ quux' xs ys =
[ ( x,
y
)
| x <- xs,
y <- ys,
then group by
-- First comment
( x
+ y
)
using
-- Second comment
groupWith -- Third comment
| x <- xs,
y <- ys,
then group by
-- First comment
( x
+ y
)
using
-- Second comment
groupWith -- Third comment
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ foo' xs ys =
[ ( x,
y
)
| x <- xs,
y <- ys,
then
-- First comment
reverse -- Second comment
| x <- xs,
y <- ys,
then
-- First comment
reverse -- Second comment
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ bar' xs ys =
[ ( x,
y
)
| x <- xs,
y <- ys,
then
-- First comment
sortWith
by
( x
+ y -- Second comment
)
| x <- xs,
y <- ys,
then
-- First comment
sortWith
by
( x
+ y -- Second comment
)
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ baz' xs ys =
[ ( x,
y
)
| x <- xs,
y <- ys,
then group using
-- First comment
permutations -- Second comment
| x <- xs,
y <- ys,
then group using
-- First comment
permutations -- Second comment
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ quux' xs ys =
[ ( x,
y
)
| x <- xs,
y <- ys,
then group by
-- First comment
( x
+ y
)
using
-- Second comment
groupWith -- Third comment
| x <- xs,
y <- ys,
then group by
-- First comment
( x
+ y
)
using
-- Second comment
groupWith -- Third comment
]
49 changes: 27 additions & 22 deletions data/examples/declaration/value/function/list-comprehensions-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@ bar x y = [(a, b) | a <- x, even a, b <- y, a != b]

barbaz x y z w =
[ (a, b, c, d) -- Foo
| a <-
x, -- Bar
b <- y, -- Baz
any even [a, b],
c <-
z
* z ^ 2, -- Bar baz
d <-
w
+ w, -- Baz bar
all
even
[ a,
b,
c,
d
]
| a <-
x, -- Bar
b <- y, -- Baz
any even [a, b],
c <-
z
* z ^ 2, -- Bar baz
d <-
w
+ w, -- Baz bar
all
even
[ a,
b,
c,
d
]
]

a = do
d <-
[ x + 1
| x <- b
]

[ c
| c <- d
]

trans =
[ x
| x <- xs,
then
reverse,
then
reverse
| x <- xs,
then
reverse,
then
reverse
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ barbaz x y z w = [
]

a = do
d <-
[ x + 1
| x <- b
]

[ c
| c <- d ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ baz x y z w =
i,
j
)
| a <- -- Foo 1
x, -- Foo 2
b <- -- Bar 1
y, -- Bar 2
| a <- -- Foo 1
x, -- Foo 2
b <- -- Bar 1
y, -- Bar 2
a
`mod` b -- Value
== 0
| c <- -- Baz 1
z
* z -- Baz 2
-- Baz 3
| d <- w -- Other
| e <- x * x -- Foo bar
| f <- -- Foo baz 1
y + y -- Foo baz 2
| h <- z + z * w ^ 2 -- Bar foo
| i <- -- Bar bar 1
a
`mod` b -- Value
== 0
| c <- -- Baz 1
z
* z -- Baz 2
-- Baz 3
| d <- w -- Other
| e <- x * x -- Foo bar
| f <- -- Foo baz 1
y + y -- Foo baz 2
| h <- z + z * w ^ 2 -- Bar foo
| i <- -- Bar bar 1
a
+ b, -- Bar bar 2
-- Bar bar 3
j <- -- Bar baz 1
a + b -- Bar baz 2
+ b, -- Bar bar 2
-- Bar bar 3
j <- -- Bar baz 1
a + b -- Bar baz 2
]
10 changes: 5 additions & 5 deletions expected-failures/hlint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ src/Extension.hs
Please, consider reporting the bug.
src/Hint/Bracket.hs
@@ -265,8 +265,11 @@
let y = noLocA $ HsApp EpAnnNotUsed a1 (nlHsPar a2),
let r = Replace Expr (toSSA e) [("a", toSSA a1), ("b", toSSA a2)] "a (b)"
let y = noLocA $ HsApp EpAnnNotUsed a1 (nlHsPar a2),
let r = Replace Expr (toSSA e) [("a", toSSA a1), ("b", toSSA a2)] "a (b)"
]
- ++ [ (suggest "Redundant bracket" (reLoc x) (reLoc y) [r]) {ideaSpan -- Special case of (v1 . v2) <$> v3
- = locA locPar}
Expand All @@ -24,9 +24,9 @@ src/Hint/Bracket.hs
+ =
+ locA locPar
+ }
| L _ (OpApp _ (L locPar (HsPar _ _ o1@(L locNoPar (OpApp _ _ (isDot -> True) _)) _)) o2 v3) <- [x],
varToStr o2 == "<$>",
let y = noLocA (OpApp EpAnnNotUsed o1 o2 v3) :: LHsExpr GhcPs,
| L _ (OpApp _ (L locPar (HsPar _ _ o1@(L locNoPar (OpApp _ _ (isDot -> True) _)) _)) o2 v3) <- [x],
varToStr o2 == "<$>",
let y = noLocA (OpApp EpAnnNotUsed o1 o2 v3) :: LHsExpr GhcPs,

Formatting is not idempotent.
Please, consider reporting the bug.
4 changes: 2 additions & 2 deletions src/Ormolu/Printer/Meat/Declaration/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ p_conDecl singleRecCon ConDeclH98 {..} =

conNameWithContextSpn =
[ RealSrcSpan real Strict.Nothing
| EpaSpan (RealSrcSpan real _) <-
mapMaybe (matchAddEpAnn AnnForall) con_ext
| EpaSpan (RealSrcSpan real _) <-
mapMaybe (matchAddEpAnn AnnForall) con_ext
]
<> fmap getLocA con_ex_tvs
<> maybeToList (fmap getLocA con_mb_cxt)
Expand Down
Loading

0 comments on commit 5c816de

Please sign in to comment.