diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-07-31 14:02:57 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-07-31 14:02:57 +0200 |
commit | 2fb2c9797442d4a44597488c07c7a27f0e0904b9 (patch) | |
tree | e9829b27407f958441ccb1b78f1354df5fbeeb42 | |
parent | ab55912b659291e6f50b844e879d0809a6c14811 (diff) | |
download | stylish-haskell-2fb2c9797442d4a44597488c07c7a27f0e0904b9.tar.gz |
Use columns setting in the LanguagePragmas filter
-rw-r--r-- | src/StylishHaskell/Config.hs | 5 | ||||
-rw-r--r-- | src/StylishHaskell/Step/LanguagePragmas.hs | 21 | ||||
-rw-r--r-- | tests/StylishHaskell/Step/LanguagePragmas/Tests.hs | 8 |
3 files changed, 17 insertions, 17 deletions
diff --git a/src/StylishHaskell/Config.hs b/src/StylishHaskell/Config.hs index 559d058..e2e6869 100644 --- a/src/StylishHaskell/Config.hs +++ b/src/StylishHaskell/Config.hs @@ -164,8 +164,9 @@ parseImports config o = Imports.step -------------------------------------------------------------------------------- parseLanguagePragmas :: Config -> A.Object -> A.Parser Step -parseLanguagePragmas _ o = LanguagePragmas.step - <$> (o A..:? "style" >>= parseEnum styles LanguagePragmas.Vertical) +parseLanguagePragmas config o = LanguagePragmas.step + <$> pure (configColumns config) + <*> (o A..:? "style" >>= parseEnum styles LanguagePragmas.Vertical) <*> o A..:? "remove_redundant" A..!= True where styles = diff --git a/src/StylishHaskell/Step/LanguagePragmas.hs b/src/StylishHaskell/Step/LanguagePragmas.hs index 1f3ccb2..9a99b6b 100644 --- a/src/StylishHaskell/Step/LanguagePragmas.hs +++ b/src/StylishHaskell/Step/LanguagePragmas.hs @@ -41,7 +41,6 @@ firstLocation = minimum . map (blockStart . fst) -------------------------------------------------------------------------------- --- | TODO: multiple lines if longer than 80 columns verticalPragmas :: [String] -> Lines verticalPragmas pragmas' = [ "{-# LANGUAGE " ++ padRight longest pragma ++ " #-}" @@ -52,25 +51,25 @@ verticalPragmas pragmas' = -------------------------------------------------------------------------------- -compactPragmas :: [String] -> Lines -compactPragmas pragmas' = wrap 80 "{-# LANGUAGE" 13 $ +compactPragmas :: Int -> [String] -> Lines +compactPragmas columns pragmas' = wrap columns "{-# LANGUAGE" 13 $ map (++ ",") (init pragmas') ++ [last pragmas', "#-}"] -------------------------------------------------------------------------------- -prettyPragmas :: Style -> [String] -> Lines -prettyPragmas Vertical = verticalPragmas -prettyPragmas Compact = compactPragmas +prettyPragmas :: Int -> Style -> [String] -> Lines +prettyPragmas _ Vertical = verticalPragmas +prettyPragmas columns Compact = compactPragmas columns -------------------------------------------------------------------------------- -step :: Style -> Bool -> Step -step style = makeStep "LanguagePragmas" . step' style +step :: Int -> Style -> Bool -> Step +step columns style = makeStep "LanguagePragmas" . step' columns style -------------------------------------------------------------------------------- -step' :: Style -> Bool -> Lines -> Module -> Lines -step' style removeRedundant ls (module', _) +step' :: Int -> Style -> Bool -> Lines -> Module -> Lines +step' columns style removeRedundant ls (module', _) | null pragmas' = ls | otherwise = applyChanges changes ls where @@ -82,7 +81,7 @@ step' style removeRedundant ls (module', _) uniques = filterRedundant $ nub $ sort $ snd =<< pragmas' loc = firstLocation pragmas' deletes = map (delete . fst) pragmas' - changes = insert loc (prettyPragmas style uniques) : deletes + changes = insert loc (prettyPragmas columns style uniques) : deletes -------------------------------------------------------------------------------- diff --git a/tests/StylishHaskell/Step/LanguagePragmas/Tests.hs b/tests/StylishHaskell/Step/LanguagePragmas/Tests.hs index d543479..1b6043f 100644 --- a/tests/StylishHaskell/Step/LanguagePragmas/Tests.hs +++ b/tests/StylishHaskell/Step/LanguagePragmas/Tests.hs @@ -27,7 +27,7 @@ tests = testGroup "StylishHaskell.Step.LanguagePragmas.Tests" -------------------------------------------------------------------------------- case01 :: Assertion -case01 = expected @=? testStep (step Vertical False) input +case01 = expected @=? testStep (step 80 Vertical False) input where input = unlines [ "{-# LANGUAGE ViewPatterns #-}" @@ -46,7 +46,7 @@ case01 = expected @=? testStep (step Vertical False) input -------------------------------------------------------------------------------- case02 :: Assertion -case02 = expected @=? testStep (step Vertical True) input +case02 = expected @=? testStep (step 80 Vertical True) input where input = unlines [ "{-# LANGUAGE BangPatterns #-}" @@ -62,7 +62,7 @@ case02 = expected @=? testStep (step Vertical True) input -------------------------------------------------------------------------------- case03 :: Assertion -case03 = expected @=? testStep (step Vertical True) input +case03 = expected @=? testStep (step 80 Vertical True) input where input = unlines [ "{-# LANGUAGE BangPatterns #-}" @@ -78,7 +78,7 @@ case03 = expected @=? testStep (step Vertical True) input -------------------------------------------------------------------------------- case04 :: Assertion -case04 = expected @=? testStep (step Compact False) input +case04 = expected @=? testStep (step 80 Compact False) input where input = unlines [ "{-# LANGUAGE TypeOperators, StandaloneDeriving, DeriveDataTypeable," |