diff --git a/lib/Language/Haskell/Stylish/Step/Data.hs b/lib/Language/Haskell/Stylish/Step/Data.hs index 972ac49e..4da96fbb 100644 --- a/lib/Language/Haskell/Stylish/Step/Data.hs +++ b/lib/Language/Haskell/Stylish/Step/Data.hs @@ -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 diff --git a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs index 58237b7d..62be7a79 100644 --- a/tests/Language/Haskell/Stylish/Step/Data/Tests.hs +++ b/tests/Language/Haskell/Stylish/Step/Data/Tests.hs @@ -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 @@ -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 @@ -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 @@ -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