summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2017-01-24 13:49:49 +0100
committerGitHub <noreply@github.com>2017-01-24 13:49:49 +0100
commitee6c4e2639ed07a35d4bf1d21757877d4bdd5360 (patch)
tree2751f9b673643d00b3856286aa561750a80a62ca
parent8efe68ba0375034e8a148ca7df741d0c35038342 (diff)
parent49dedad84701d7c0af13edb2e49284373e4e5760 (diff)
downloadstylish-haskell-ee6c4e2639ed07a35d4bf1d21757877d4bdd5360.tar.gz
Merge pull request #143 from themoritz/fix/keep-safe-and-source
Keep `safe` and `{-# SOURCE #-}` import annotations
-rw-r--r--lib/Language/Haskell/Stylish/Step/Imports.hs17
-rw-r--r--tests/Language/Haskell/Stylish/Step/Imports/Tests.hs19
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs
index 334fa15..29b8cc2 100644
--- a/lib/Language/Haskell/Stylish/Step/Imports.hs
+++ b/lib/Language/Haskell/Stylish/Step/Imports.hs
@@ -235,6 +235,8 @@ prettyImport columns Options{..} padQualified padName longest imp
base' baseName importAs hasHiding' = unwords $ concat $ filter (not . null)
[ ["import"]
+ , source
+ , safe
, qualified
, show <$> maybeToList (H.importPkg imp)
, [baseName]
@@ -259,9 +261,22 @@ prettyImport columns Options{..} padQualified padName longest imp
qualified
| H.importQualified imp = ["qualified"]
- | padQualified = [" "]
+ | padQualified =
+ if H.importSrc imp
+ then []
+ else if H.importSafe imp
+ then [" "]
+ else [" "]
| otherwise = []
+ safe
+ | H.importSafe imp = ["safe"]
+ | otherwise = []
+
+ source
+ | H.importSrc imp = ["{-# SOURCE #-}"]
+ | otherwise = []
+
mapSpecs f = case importSpecs of
Nothing -> [] -- Import everything
Just [] -> ["()"] -- Instance only imports
diff --git a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
index 5ca60de..c3178ac 100644
--- a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
+++ b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
@@ -46,6 +46,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests"
, testCase "case 19b" case19b
, testCase "case 19d" case19c
, testCase "case 19d" case19d
+ , testCase "case 20" case20
]
@@ -512,3 +513,21 @@ case19input = unlines
, ""
, "import Data.List (foldl', intercalate, intersperse)"
]
+
+--------------------------------------------------------------------------------
+case20 :: Assertion
+case20 = expected
+ @=? testStep (step 80 defaultOptions) input'
+ where
+ expected = unlines
+ [ "import {-# SOURCE #-} Data.ByteString as BS"
+ , "import qualified Data.Map as Map"
+ , "import Data.Set (empty)"
+ , "import {-# SOURCE #-} qualified Data.Text as T"
+ ]
+ input' = unlines
+ [ "import {-# SOURCE #-} Data.ByteString as BS"
+ , "import {-# SOURCE #-} qualified Data.Text as T"
+ , "import qualified Data.Map as Map"
+ , "import Data.Set (empty)"
+ ]