summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorMaxim Koltsov <kolmax94@gmail.com>2020-02-02 15:18:24 +0300
committerGitHub <noreply@github.com>2020-02-02 13:18:24 +0100
commit41dcda2a34b5f12f3fa91480bfe2aaeb4afa90e5 (patch)
tree84f661b8d74b8a6525ed1c24d3319b053ae1f151 /lib
parentd2594404a89839edc3ac44ea1fed3f99c2aade68 (diff)
downloadstylish-haskell-41dcda2a34b5f12f3fa91480bfe2aaeb4afa90e5.tar.gz
Disable formatting of data types without records (#265)
Diffstat (limited to 'lib')
-rw-r--r--lib/Language/Haskell/Stylish/Step/Data.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Language/Haskell/Stylish/Step/Data.hs b/lib/Language/Haskell/Stylish/Step/Data.hs
index 94aaf22..681c7c8 100644
--- a/lib/Language/Haskell/Stylish/Step/Data.hs
+++ b/lib/Language/Haskell/Stylish/Step/Data.hs
@@ -45,9 +45,15 @@ commentsWithin lb = filter within
changeDecl :: [Comment] -> Int -> H.Decl LineBlock -> Maybe ChangeLine
changeDecl _ _ (H.DataDecl _ (H.DataType _) Nothing _ [] _) = Nothing
-changeDecl allComments indentSize (H.DataDecl block (H.DataType _) Nothing dhead decls derivings) =
- Just $ change block (const $ concat newLines)
+changeDecl allComments indentSize (H.DataDecl block (H.DataType _) Nothing dhead decls derivings)
+ | hasRecordFields = Just $ change block (const $ concat newLines)
+ | otherwise = Nothing
where
+ hasRecordFields = any
+ (\qual -> case qual of
+ (H.QualConDecl _ _ _ (H.RecDecl {})) -> True
+ _ -> False)
+ decls
newLines = fmap constructors zipped ++ [fmap (indented . H.prettyPrint) derivings]
zipped = zip decls ([1..] ::[Int])
constructors (decl, 1) = processConstructor allComments typeConstructor indentSize decl