Skip to content

Commit ba8f471

Browse files
authored
Deriving alignment for enums (#424)
* Failing test added * Haddoc comment added * Deriving alignment behavior changed & tests updated * Test data name changed (just to look prettier)
1 parent 64860c2 commit ba8f471

File tree

2 files changed

+19
-4
lines changed
  • lib/Language/Haskell/Stylish/Step
  • tests/Language/Haskell/Stylish/Step/Data

2 files changed

+19
-4
lines changed

lib/Language/Haskell/Stylish/Step/Data.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ putDataDecl cfg@Config {..} decl = do
196196
let derivingComments = deepAnnComments (GHC.dd_derivs defn)
197197

198198
when (hasDeriving decl) do
199-
if onelineEnum && null derivingComments then
200-
space
199+
if onelineEnum && null derivingComments then do
200+
newline
201+
spaces cDeriving
201202
else do
202203
forM_ derivingComments $ \lc -> do
203204
newline

tests/Language/Haskell/Stylish/Step/Data/Tests.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
7878
, testCase "case 63 (issue #338)" case63
7979
, testCase "case 64" case64
8080
, testCase "case 65" case65
81+
, testCase "case 66 (issue #411)" case66
8182
]
8283

8384
case00 :: Assertion
@@ -424,7 +425,8 @@ case20 = assertSnippet (step indentIndentStyle) input input
424425
input =
425426
[ "module Herp where"
426427
, ""
427-
, "data Tag = Title | Text deriving (Eq, Show)"
428+
, "data Tag = Title | Text"
429+
, " deriving (Eq, Show)"
428430
]
429431

430432
case21 :: Assertion
@@ -1161,7 +1163,8 @@ case55 :: Assertion
11611163
case55 = assertSnippet (step sameSameNoSortStyle) input expected
11621164
where
11631165
input =
1164-
[ "data Foo = Foo deriving (Z, Y, X, Bar, Abcd)"
1166+
[ "data Foo = Foo"
1167+
, " deriving (Z, Y, X, Bar, Abcd)"
11651168
]
11661169

11671170
expected = input
@@ -1367,6 +1370,17 @@ case65 = assertSnippet (step indentIndentStyle) input input
13671370
, " deriving (Show)"
13681371
]
13691372

1373+
-- | Deriving alignment for enums
1374+
--
1375+
-- Regression test for https://github.com/haskell/stylish-haskell/issues/411
1376+
case66 :: Assertion
1377+
case66 = assertSnippet (step indentIndentStyle) input input
1378+
where
1379+
input =
1380+
[ "data Foo = A | B | C"
1381+
, " deriving (Eq, Show)"
1382+
]
1383+
13701384
sameSameStyle :: Config
13711385
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns
13721386

0 commit comments

Comments
 (0)