Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Language/Haskell/Stylish/Step/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ putDataDecl cfg@Config {..} decl = do
let derivingComments = deepAnnComments (GHC.dd_derivs defn)

when (hasDeriving decl) do
if onelineEnum && null derivingComments then
space
if onelineEnum && null derivingComments then do
newline
spaces cDeriving
else do
forM_ derivingComments $ \lc -> do
newline
Expand Down
18 changes: 16 additions & 2 deletions tests/Language/Haskell/Stylish/Step/Data/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
, testCase "case 63 (issue #338)" case63
, testCase "case 64" case64
, testCase "case 65" case65
, testCase "case 66 (issue #411)" case66
]

case00 :: Assertion
Expand Down Expand Up @@ -424,7 +425,8 @@ case20 = assertSnippet (step indentIndentStyle) input input
input =
[ "module Herp where"
, ""
, "data Tag = Title | Text deriving (Eq, Show)"
, "data Tag = Title | Text"
, " deriving (Eq, Show)"
]

case21 :: Assertion
Expand Down Expand Up @@ -1161,7 +1163,8 @@ case55 :: Assertion
case55 = assertSnippet (step sameSameNoSortStyle) input expected
where
input =
[ "data Foo = Foo deriving (Z, Y, X, Bar, Abcd)"
[ "data Foo = Foo"
, " deriving (Z, Y, X, Bar, Abcd)"
]

expected = input
Expand Down Expand Up @@ -1367,6 +1370,17 @@ case65 = assertSnippet (step indentIndentStyle) input input
, " deriving (Show)"
]

-- | Deriving alignment for enums
--
-- Regression test for https://github.com/haskell/stylish-haskell/issues/411
case66 :: Assertion
case66 = assertSnippet (step indentIndentStyle) input input
where
input =
[ "data Foo = A | B | C"
, " deriving (Eq, Show)"
]

sameSameStyle :: Config
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns

Expand Down