summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--data/stylish-haskell.yaml17
-rw-r--r--src/Language/Haskell/Stylish/Config.hs3
-rw-r--r--src/Language/Haskell/Stylish/Step/Imports.hs7
-rw-r--r--tests/Language/Haskell/Stylish/Step/Imports/Tests.hs49
4 files changed, 65 insertions, 11 deletions
diff --git a/data/stylish-haskell.yaml b/data/stylish-haskell.yaml
index 3d4e98a..28b994e 100644
--- a/data/stylish-haskell.yaml
+++ b/data/stylish-haskell.yaml
@@ -80,6 +80,23 @@ steps:
# This option affects 'list_align' and 'long_list_align'.
list_padding: 4
+ # Separate lists option affects formating of import list for type
+ # or class. The only difference is single space between type and list
+ # of constructors, selectors and class functions.
+ #
+ # - true: There is single space between Foldable type and list of it's
+ # functions.
+ #
+ # > import Data.Foldable (Foldable (fold, foldl, foldMap))
+ #
+ # - false: There is no space between Foldable type and list of it's
+ # functions.
+ #
+ # > import Data.Foldable (Foldable(fold, foldl, foldMap))
+ #
+ # Default: true
+ separate_lists: true
+
# Language pragmas
- language_pragmas:
# We can generate different styles of language pragma lists.
diff --git a/src/Language/Haskell/Stylish/Config.hs b/src/Language/Haskell/Stylish/Config.hs
index c176eb6..b8ae588 100644
--- a/src/Language/Haskell/Stylish/Config.hs
+++ b/src/Language/Haskell/Stylish/Config.hs
@@ -169,8 +169,9 @@ parseImports config o = Imports.step
<*> (o A..:? "list_align" >>= parseEnum listAligns Imports.AfterAlias)
<*> (o A..:? "long_list_align"
>>= parseEnum longListAligns Imports.Inline)
- <*> (maybe 4 (max 1) <$> o A..:? "list_padding"))
+ <*> (maybe 4 (max 1) <$> o A..:? "list_padding")
-- ^ Padding have to be at least 1. Default is 4.
+ <*> o A..:? "separate_lists" A..!= True)
where
aligns =
[ ("global", Imports.Global)
diff --git a/src/Language/Haskell/Stylish/Step/Imports.hs b/src/Language/Haskell/Stylish/Step/Imports.hs
index f47d594..2dd6a2a 100644
--- a/src/Language/Haskell/Stylish/Step/Imports.hs
+++ b/src/Language/Haskell/Stylish/Step/Imports.hs
@@ -31,6 +31,7 @@ data Align = Align
, listAlign :: ListAlign
, longListAlign :: LongListAlign
, listPadding :: Int
+ , separateLists :: Bool
}
deriving (Eq, Show)
@@ -203,7 +204,11 @@ prettyImport columns Align{..} padQualified padName longest imp =
mapSpecs f = case importSpecs of
Nothing -> [] -- Import everything
Just [] -> ["()"] -- Instance only imports
- Just is -> f $ map prettyImportSpec is
+ Just is -> f $ map format is
+ where
+ format
+ | separateLists = prettyImportSpec
+ | otherwise = H.prettyPrint
--------------------------------------------------------------------------------
diff --git a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
index 95f003e..f7f840d 100644
--- a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
+++ b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
@@ -17,7 +17,7 @@ import Language.Haskell.Stylish.Tests.Util
--------------------------------------------------------------------------------
defaultAlign :: Align
-defaultAlign = Align Global AfterAlias Inline 4
+defaultAlign = Align Global AfterAlias Inline 4 True
--------------------------------------------------------------------------------
@@ -42,6 +42,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests"
, testCase "case 13" case13
, testCase "case 14" case14
, testCase "case 15" case15
+ , testCase "case 16" case16
]
@@ -180,7 +181,8 @@ case07 = expected @=? testStep (step 80 $ fromImportAlign File) input'
--------------------------------------------------------------------------------
case08 :: Assertion
-case08 = expected @=? testStep (step 80 $ Align Global WithAlias Inline 4) input
+case08 = expected
+ @=? testStep (step 80 $ Align Global WithAlias Inline 4 True) input
where
expected = unlines
[ "module Herp where"
@@ -202,7 +204,8 @@ case08 = expected @=? testStep (step 80 $ Align Global WithAlias Inline 4) input
--------------------------------------------------------------------------------
case09 :: Assertion
-case09 = expected @=? testStep (step 80 $ Align Global WithAlias Multiline 4) input
+case09 = expected
+ @=? testStep (step 80 $ Align Global WithAlias Multiline 4 True) input
where
expected = unlines
[ "module Herp where"
@@ -235,7 +238,8 @@ case09 = expected @=? testStep (step 80 $ Align Global WithAlias Multiline 4) in
--------------------------------------------------------------------------------
case10 :: Assertion
-case10 = expected @=? testStep (step 40 $ Align Group WithAlias Multiline 4) input
+case10 = expected
+ @=? testStep (step 40 $ Align Group WithAlias Multiline 4 True) input
where
expected = unlines
[ "module Herp where"
@@ -273,7 +277,8 @@ case10 = expected @=? testStep (step 40 $ Align Group WithAlias Multiline 4) inp
--------------------------------------------------------------------------------
case11 :: Assertion
-case11 = expected @=? testStep (step 80 $ Align Group NewLine Inline 4) input
+case11 = expected
+ @=? testStep (step 80 $ Align Group NewLine Inline 4 True) input
where
expected = unlines
[ "module Herp where"
@@ -300,7 +305,8 @@ case11 = expected @=? testStep (step 80 $ Align Group NewLine Inline 4) input
--------------------------------------------------------------------------------
case12 :: Assertion
-case12 = expected @=? testStep (step 80 $ Align Group NewLine Inline 2) input'
+case12 = expected
+ @=? testStep (step 80 $ Align Group NewLine Inline 2 True) input'
where
input' = unlines
[ "import Data.List (map)"
@@ -315,7 +321,7 @@ case12 = expected @=? testStep (step 80 $ Align Group NewLine Inline 2) input'
--------------------------------------------------------------------------------
case13 :: Assertion
case13 = expected
- @=? testStep (step 80 $ Align None WithAlias InlineWithBreak 4) input'
+ @=? testStep (step 80 $ Align None WithAlias InlineWithBreak 4 True) input'
where
input' = unlines
[ "import qualified Data.List as List (concat, foldl, foldr, head, init,"
@@ -332,7 +338,8 @@ case13 = expected
--------------------------------------------------------------------------------
case14 :: Assertion
case14 = expected
- @=? testStep (step 80 $ Align None WithAlias InlineWithBreak 10) expected
+ @=? testStep
+ (step 80 $ Align None WithAlias InlineWithBreak 10 True) expected
where
expected = unlines
[ "import qualified Data.List as List (concat, map, null, reverse, tail, (++))"
@@ -341,7 +348,7 @@ case14 = expected
--------------------------------------------------------------------------------
case15 :: Assertion
case15 = expected
- @=? testStep (step 80 $ Align None AfterAlias Multiline 4) input'
+ @=? testStep (step 80 $ Align None AfterAlias Multiline 4 True) input'
where
expected = unlines
[ "import Data.Acid (AcidState)"
@@ -362,3 +369,27 @@ case15 = expected
, ""
, "import qualified Herp.Derp.Internal.Types.Foobar as Internal (foo, bar)"
]
+
+
+--------------------------------------------------------------------------------
+case16 :: Assertion
+case16 = expected
+ @=? testStep (step 80 $ Align None AfterAlias Multiline 4 False) input'
+ where
+ expected = unlines
+ [ "import Data.Acid (AcidState)"
+ , "import Data.Default.Class (Default(def))"
+ , ""
+ , "import Data.Maybe (Maybe(Just, Nothing))"
+ , ""
+ , "import Data.Foo (Foo(Foo, Bar), Goo(Goo))"
+ ]
+
+ input' = unlines
+ [ "import Data.Acid (AcidState)"
+ , "import Data.Default.Class (Default(def))"
+ , ""
+ , "import Data.Maybe (Maybe (Just, Nothing))"
+ , ""
+ , "import Data.Foo (Foo (Foo,Bar), Goo(Goo))"
+ ]