stylish-haskell 0.8.0.0 → 0.8.1.0
raw patch · 6 files changed
+158/−33 lines, 6 filesdep ~optparse-applicativePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: optparse-applicative
API changes (from Hackage documentation)
+ Language.Haskell.Stylish.Step.Imports: [padModuleNames] :: Options -> Bool
+ Language.Haskell.Stylish.Step.Imports: [spaceSurround] :: Options -> Bool
- Language.Haskell.Stylish.Step.Imports: Options :: ImportAlign -> ListAlign -> LongListAlign -> EmptyListAlign -> ListPadding -> Bool -> Options
+ Language.Haskell.Stylish.Step.Imports: Options :: ImportAlign -> ListAlign -> Bool -> LongListAlign -> EmptyListAlign -> ListPadding -> Bool -> Bool -> Options
Files
- CHANGELOG +5/−0
- data/stylish-haskell.yaml +35/−0
- lib/Language/Haskell/Stylish/Config.hs +3/−1
- lib/Language/Haskell/Stylish/Step/Imports.hs +24/−15
- stylish-haskell.cabal +2/−2
- tests/Language/Haskell/Stylish/Step/Imports/Tests.hs +89/−15
CHANGELOG view
@@ -1,5 +1,10 @@ # CHANGELOG +- 0.8.1.0 (2017-06-19)+ * Add `pad_module_names` option (by Yuriy Syrovetskiy)+ * Add `space_surround` option to import styling (by Linus Arver)+ * Bump `optparse-applicative` to 0.14+ - 0.8.0.0 * Remove `MagicHash` from whitelisted language extensions, since it was causing parsing errors (by Artyom Kazak)
data/stylish-haskell.yaml view
@@ -64,6 +64,25 @@ # Default: after_alias list_align: after_alias + # Right-pad the module names to align imports in a group:+ #+ # - true: a little more readable+ #+ # > import qualified Data.List as List (concat, foldl, foldr,+ # > init, last, length)+ # > import qualified Data.List.Extra as List (concat, foldl, foldr,+ # > init, last, length)+ #+ # - false: diff-safe+ #+ # > import qualified Data.List as List (concat, foldl, foldr, init,+ # > last, length)+ # > import qualified Data.List.Extra as List (concat, foldl, foldr,+ # > init, last, length)+ #+ # Default: true+ pad_module_names: true+ # Long list align style takes effect when import is too long. This is # determined by 'columns' setting. #@@ -125,6 +144,22 @@ # # Default: true separate_lists: true++ # Space surround option affects formatting of import lists on a single+ # line. The only difference is single space after the initial+ # parenthesis and a single space before the terminal parenthesis.+ #+ # - true: There is single space associated with the enclosing+ # parenthesis.+ #+ # > import Data.Foo ( foo )+ #+ # - false: There is no space associated with the enclosing parenthesis+ #+ # > import Data.Foo (foo)+ #+ # Default: false+ space_surround: false # Language pragmas - language_pragmas:
lib/Language/Haskell/Stylish/Config.hs view
@@ -184,13 +184,15 @@ <*> (Imports.Options <$> (o A..:? "align" >>= parseEnum aligns (def Imports.importAlign)) <*> (o A..:? "list_align" >>= parseEnum listAligns (def Imports.listAlign))+ <*> (o A..:? "pad_module_names" A..!= def Imports.padModuleNames) <*> (o A..:? "long_list_align" >>= parseEnum longListAligns (def Imports.longListAlign)) -- Note that padding has to be at least 1. Default is 4. <*> (o A..:? "empty_list_align" >>= parseEnum emptyListAligns (def Imports.emptyListAlign)) <*> o A..:? "list_padding" A..!= (def Imports.listPadding)- <*> o A..:? "separate_lists" A..!= (def Imports.separateLists))+ <*> o A..:? "separate_lists" A..!= (def Imports.separateLists)+ <*> o A..:? "space_surround" A..!= (def Imports.spaceSurround)) where def f = f Imports.defaultOptions
lib/Language/Haskell/Stylish/Step/Imports.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-} -------------------------------------------------------------------------------- module Language.Haskell.Stylish.Step.Imports ( Options (..)@@ -16,16 +16,16 @@ -------------------------------------------------------------------------------- import Control.Arrow ((&&&)) import Control.Monad (void)-import Data.Monoid ((<>))+import qualified Data.Aeson as A+import qualified Data.Aeson.Types as A import Data.Char (toLower) import Data.List (intercalate, sortBy)+import qualified Data.Map as M import Data.Maybe (isJust, maybeToList)+import Data.Monoid ((<>)) import Data.Ord (comparing)-import qualified Data.Map as M import qualified Data.Set as S import qualified Language.Haskell.Exts as H-import qualified Data.Aeson as A-import qualified Data.Aeson.Types as A --------------------------------------------------------------------------------@@ -38,20 +38,24 @@ data Options = Options { importAlign :: ImportAlign , listAlign :: ListAlign+ , padModuleNames :: Bool , longListAlign :: LongListAlign , emptyListAlign :: EmptyListAlign , listPadding :: ListPadding , separateLists :: Bool+ , spaceSurround :: Bool } deriving (Eq, Show) defaultOptions :: Options defaultOptions = Options { importAlign = Global , listAlign = AfterAlias+ , padModuleNames = True , longListAlign = Inline , emptyListAlign = Inherit , listPadding = LPConstant 4 , separateLists = True+ , spaceSurround = False } data ListPadding@@ -187,9 +191,9 @@ recomposeImportSpec :: (ImportEntity l, ImportPortion l) -> H.ImportSpec l recomposeImportSpec (e, p) = case e of ImportClassOrData l n -> case p of- ImportSome [] -> H.IAbs l (H.NoNamespace l) n- ImportSome names -> H.IThingWith l n names- ImportAll -> H.IThingAll l n+ ImportSome [] -> H.IAbs l (H.NoNamespace l) n+ ImportSome names -> H.IThingWith l n names+ ImportAll -> H.IThingAll l n ImportVar l n -> H.IVar l n ImportOther l space n -> H.IAbs l space n @@ -274,27 +278,27 @@ | otherwise = shortWrap emptyWrap = case emptyListAlign of- Inherit -> inlineWrap+ Inherit -> inlineWrap RightAfter -> [paddedNoSpecBase ++ " ()"] inlineWrap = inlineWrapper $ mapSpecs $ withInit (++ ",")- . withHead ("(" ++)- . withLast (++ ")")+ . withHead (("(" ++ maybeSpace) ++)+ . withLast (++ (maybeSpace ++ ")")) inlineWrapper = case listAlign of NewLine -> (paddedNoSpecBase :) . wrapRest columns listPadding' WithAlias -> wrap columns paddedBase (inlineBaseLength + 1) -- Add 1 extra space to ensure same padding as in original code.- AfterAlias -> withTail (' ' :)+ AfterAlias -> withTail ((' ' : maybeSpace) ++) . wrap columns paddedBase (afterAliasBaseLength + 1) inlineWithBreakWrap = paddedNoSpecBase : wrapRest columns listPadding' ( mapSpecs $ withInit (++ ",")- . withHead ("(" ++)- . withLast (++ ")"))+ . withHead (("(" ++ maybeSpace) ++)+ . withLast (++ (maybeSpace ++ ")"))) inlineToMultilineWrap | length inlineWithBreakWrap > 2@@ -370,7 +374,11 @@ Just [] -> ["()"] -- Instance only imports Just is -> f $ map (prettyImportSpec separateLists) is + maybeSpace = case spaceSurround of+ True -> " "+ False -> "" + -------------------------------------------------------------------------------- prettyImportGroup :: Int -> Options -> Bool -> Int -> [H.ImportDecl LineBlock]@@ -380,12 +388,13 @@ sortBy compareImports imps where align' = importAlign align+ padModuleNames' = padModuleNames align longest' = case align' of Group -> longestImport imps _ -> longest - padName = align' /= None+ padName = align' /= None && padModuleNames' padQual = case align' of Global -> True
stylish-haskell.cabal view
@@ -1,5 +1,5 @@ Name: stylish-haskell-Version: 0.8.0.0+Version: 0.8.1.0 Synopsis: Haskell code prettifier Homepage: https://github.com/jaspervdj/stylish-haskell License: BSD3@@ -68,7 +68,7 @@ Build-depends: stylish-haskell, strict >= 0.3 && < 0.4,- optparse-applicative >= 0.12 && < 0.14,+ optparse-applicative >= 0.12 && < 0.15, -- Copied from regular dependencies... aeson >= 0.6 && < 1.3, base >= 4.8 && < 5,
tests/Language/Haskell/Stylish/Step/Imports/Tests.hs view
@@ -49,6 +49,9 @@ , testCase "case 20" case20 , testCase "case 21" case21 , testCase "case 22" case22+ , testCase "case 23" case23+ , testCase "case 24" case24+ , testCase "case 25" case25 ] @@ -188,7 +191,7 @@ -------------------------------------------------------------------------------- case08 :: Assertion case08 = expected- @=? testStep (step 80 $ Options Global WithAlias Inline Inherit (LPConstant 4) True) input+ @=? testStep (step 80 $ Options Global WithAlias True Inline Inherit (LPConstant 4) True False) input where expected = unlines [ "module Herp where"@@ -211,7 +214,7 @@ -------------------------------------------------------------------------------- case09 :: Assertion case09 = expected- @=? testStep (step 80 $ Options Global WithAlias Multiline Inherit (LPConstant 4) True) input+ @=? testStep (step 80 $ Options Global WithAlias True Multiline Inherit (LPConstant 4) True False) input where expected = unlines [ "module Herp where"@@ -245,7 +248,7 @@ -------------------------------------------------------------------------------- case10 :: Assertion case10 = expected- @=? testStep (step 40 $ Options Group WithAlias Multiline Inherit (LPConstant 4) True) input+ @=? testStep (step 40 $ Options Group WithAlias True Multiline Inherit (LPConstant 4) True False) input where expected = unlines [ "module Herp where"@@ -284,7 +287,7 @@ -------------------------------------------------------------------------------- case11 :: Assertion case11 = expected- @=? testStep (step 80 $ Options Group NewLine Inline Inherit (LPConstant 4) True) input+ @=? testStep (step 80 $ Options Group NewLine True Inline Inherit (LPConstant 4) True False) input where expected = unlines [ "module Herp where"@@ -312,7 +315,7 @@ -------------------------------------------------------------------------------- case12 :: Assertion case12 = expected- @=? testStep (step 80 $ Options Group NewLine Inline Inherit (LPConstant 2) True) input'+ @=? testStep (step 80 $ Options Group NewLine True Inline Inherit (LPConstant 2) True False) input' where input' = unlines [ "import Data.List (map)"@@ -327,7 +330,7 @@ -------------------------------------------------------------------------------- case13 :: Assertion case13 = expected- @=? testStep (step 80 $ Options None WithAlias InlineWithBreak Inherit (LPConstant 4) True) input'+ @=? testStep (step 80 $ Options None WithAlias True InlineWithBreak Inherit (LPConstant 4) True False) input' where input' = unlines [ "import qualified Data.List as List (concat, foldl, foldr, head, init,"@@ -345,7 +348,7 @@ case14 :: Assertion case14 = expected @=? testStep- (step 80 $ Options None WithAlias InlineWithBreak Inherit (LPConstant 10) True) expected+ (step 80 $ Options None WithAlias True InlineWithBreak Inherit (LPConstant 10) True False) expected where expected = unlines [ "import qualified Data.List as List (concat, map, null, reverse, tail, (++))"@@ -355,7 +358,7 @@ -------------------------------------------------------------------------------- case15 :: Assertion case15 = expected- @=? testStep (step 80 $ Options None AfterAlias Multiline Inherit (LPConstant 4) True) input'+ @=? testStep (step 80 $ Options None AfterAlias True Multiline Inherit (LPConstant 4) True False) input' where expected = unlines [ "import Data.Acid (AcidState)"@@ -381,7 +384,7 @@ -------------------------------------------------------------------------------- case16 :: Assertion case16 = expected- @=? testStep (step 80 $ Options None AfterAlias Multiline Inherit (LPConstant 4) False) input'+ @=? testStep (step 80 $ Options None AfterAlias True Multiline Inherit (LPConstant 4) False False) input' where expected = unlines [ "import Data.Acid (AcidState)"@@ -405,7 +408,7 @@ -------------------------------------------------------------------------------- case17 :: Assertion case17 = expected- @=? testStep (step 80 $ Options None AfterAlias Multiline Inherit (LPConstant 4) True) input'+ @=? testStep (step 80 $ Options None AfterAlias True Multiline Inherit (LPConstant 4) True False) input' where expected = unlines [ "import Control.Applicative (Applicative (pure, (<*>)))"@@ -423,7 +426,7 @@ -------------------------------------------------------------------------------- case18 :: Assertion case18 = expected @=? testStep- (step 40 $ Options None AfterAlias InlineToMultiline Inherit (LPConstant 4) True) input'+ (step 40 $ Options None AfterAlias True InlineToMultiline Inherit (LPConstant 4) True False) input' where expected = unlines ----------------------------------------@@ -450,7 +453,7 @@ -------------------------------------------------------------------------------- case19 :: Assertion case19 = expected @=? testStep- (step 40 $ Options Global NewLine InlineWithBreak RightAfter (LPConstant 17) True) case19input+ (step 40 $ Options Global NewLine True InlineWithBreak RightAfter (LPConstant 17) True False) case19input where expected = unlines ----------------------------------------@@ -465,7 +468,7 @@ case19b :: Assertion case19b = expected @=? testStep- (step 40 $ Options File NewLine InlineWithBreak RightAfter (LPConstant 17) True) case19input+ (step 40 $ Options File NewLine True InlineWithBreak RightAfter (LPConstant 17) True False) case19input where expected = unlines ----------------------------------------@@ -480,7 +483,7 @@ case19c :: Assertion case19c = expected @=? testStep- (step 40 $ Options File NewLine InlineWithBreak RightAfter LPModuleName True) case19input+ (step 40 $ Options File NewLine True InlineWithBreak RightAfter LPModuleName True False) case19input where expected = unlines ----------------------------------------@@ -495,7 +498,7 @@ case19d :: Assertion case19d = expected @=? testStep- (step 40 $ Options Global NewLine InlineWithBreak RightAfter LPModuleName True) case19input+ (step 40 $ Options Global NewLine True InlineWithBreak RightAfter LPModuleName True False) case19input where expected = unlines ----------------------------------------@@ -588,4 +591,75 @@ -- but doesn't fit when "foo" is included into the calculation , "import \"foo\" B (someLongName, someLongerName, " ++ "theLongestNameYet, shortName)"+ ]++--------------------------------------------------------------------------------+case23 :: Assertion+case23 = expected+ @=? testStep (step 40 $ Options None AfterAlias False Inline Inherit (LPConstant 4) True True) input'+ where+ expected = unlines+ [ "import Data.Acid ( AcidState )"+ , "import Data.Default.Class ( Default (def) )"+ , ""+ , "import Data.Monoid ( (<>) )"+ , ""+ , "import Data.ALongName.Foo ( Boo, Foo,"+ , " Goo )"+ ]++ input' = unlines+ [ "import Data.Acid (AcidState)"+ , "import Data.Default.Class (Default(def))"+ , ""+ , "import Data.Monoid ((<>) )"+ , ""+ , "import Data.ALongName.Foo (Foo, Goo, Boo)"+ ]++--------------------------------------------------------------------------------+case24 :: Assertion+case24 = expected+ @=? testStep (step 40 $ Options None AfterAlias False InlineWithBreak Inherit (LPConstant 4) True True) input'+ where+ expected = unlines+ [ "import Data.Acid ( AcidState )"+ , "import Data.Default.Class"+ , " ( Default (def) )"+ , ""+ , "import Data.ALongName.Foo"+ , " ( BooReallyLong, FooReallyLong,"+ , " GooReallyLong )"+ ]++ input' = unlines+ [ "import Data.Acid (AcidState)"+ , "import Data.Default.Class (Default(def))"+ , ""+ , "import Data.ALongName.Foo (FooReallyLong, " +++ "GooReallyLong, BooReallyLong)"+ ]++--------------------------------------------------------------------------------+case25 :: Assertion+case25 = expected+ @=? testStep (step 80 $ Options Group AfterAlias False Multiline Inherit (LPConstant 4) False False) input'+ where+ expected = unlines+ [ "import Data.Acid (AcidState)"+ , "import Data.Default.Class (Default(def))"+ , ""+ , "import Data.Maybe (Maybe(Just, Nothing))"+ , "import qualified Data.Maybe.Extra (Maybe(Just, Nothing))"+ , ""+ , "import Data.Foo (Foo(Bar, Foo), Goo(Goo))"+ ]+ input' = unlines+ [ "import Data.Acid (AcidState)"+ , "import Data.Default.Class (Default(def))"+ , ""+ , "import Data.Maybe (Maybe (Just, Nothing))"+ , "import qualified Data.Maybe.Extra (Maybe(Just, Nothing))"+ , ""+ , "import Data.Foo (Foo (Foo,Bar), Goo(Goo))" ]