stylish-haskell 0.9.2.2 → 0.9.3.0
raw patch · 9 files changed
+164/−14 lines, 9 filesdep ~optparse-applicativePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: optparse-applicative
API changes (from Hackage documentation)
+ Language.Haskell.Stylish.Step.Imports: WithModuleName :: ListAlign
Files
- CHANGELOG +7/−0
- README.markdown +7/−4
- data/stylish-haskell.yaml +12/−0
- lib/Language/Haskell/Stylish/Config.hs +4/−3
- lib/Language/Haskell/Stylish/Step/Imports.hs +7/−3
- lib/Language/Haskell/Stylish/Step/TrailingWhitespace.hs +6/−1
- stylish-haskell.cabal +2/−2
- tests/Language/Haskell/Stylish/Step/Imports/Tests.hs +114/−0
- tests/Language/Haskell/Stylish/Step/TrailingWhitespace/Tests.hs +5/−1
CHANGELOG view
@@ -1,5 +1,12 @@ # CHANGELOG +- 0.9.3.0 (2019-10-08)+ * Bump `optparse-applicative` to 0.15+ * Don't remove page breaks in the trailing whitespace step (by Chris+ Perivolaropoulos)+ * Add `with_module_name` option to `list_align` for import styling (by+ Rupert Horlick)+ - 0.9.2.2 (2019-06-12) * Bump `semigroups` to 0.19 * Bump `haskell-src-exts` to 1.21
README.markdown view
@@ -124,7 +124,8 @@ and then use `gq`. -Alternatively, [vim-autoformat] supports stylish-haskell. To have it automatically reformat the files on save, add to your vimrc:+Alternatively, [vim-autoformat] supports stylish-haskell. To have it+automatically reformat the files on save, add to your vimrc: ```vim autocmd BufWrite *.hs :Autoformat@@ -132,12 +133,14 @@ autocmd FileType haskell let b:autoformat_autoindent=0 ``` -[vim-autoformat]: https://github.com/Chiel92/vim-autoformat+There are also plugins that run stylish-haskell automatically when you save a+Haskell file: -There is also the [vim-stylish-haskell] plugin, which runs stylish-haskell-automatically when you save a Haskell file.+* [vim-stylish-haskell]+* [vim-stylishask] [vim-stylish-haskell]: https://github.com/nbouscal/vim-stylish-haskell+[vim-stylishask]: https://github.com/alx741/vim-stylishask Emacs integration -----------------
data/stylish-haskell.yaml view
@@ -56,6 +56,18 @@ # > import qualified Data.List as List (concat, foldl, foldr, head, # > init, last, length) #+ # - with_module_name: Import list is aligned `list_padding` spaces after+ # the module name.+ #+ # > import qualified Data.List as List (concat, foldl, foldr, head,+ # init, last, length)+ #+ # This is mainly intended for use with `pad_module_names: false`.+ #+ # > import qualified Data.List as List (concat, foldl, foldr, head,+ # init, last, length, scanl, scanr, take, drop,+ # sort, nub)+ # # - new_line: Import list starts always on new line. # # > import qualified Data.List as List
lib/Language/Haskell/Stylish/Config.hs view
@@ -209,9 +209,10 @@ ] listAligns =- [ ("new_line", Imports.NewLine)- , ("with_alias", Imports.WithAlias)- , ("after_alias", Imports.AfterAlias)+ [ ("new_line", Imports.NewLine)+ , ("with_module_name", Imports.WithModuleName)+ , ("with_alias", Imports.WithAlias)+ , ("after_alias", Imports.AfterAlias) ] longListAligns =
lib/Language/Haskell/Stylish/Step/Imports.hs view
@@ -72,6 +72,7 @@ data ListAlign = NewLine+ | WithModuleName | WithAlias | AfterAlias deriving (Eq, Show)@@ -291,10 +292,11 @@ . withLast (++ (maybeSpace ++ ")")) inlineWrapper = case listAlign of- NewLine -> (paddedNoSpecBase :) . wrapRest columns listPadding'- WithAlias -> wrap columns paddedBase (inlineBaseLength + 1)+ NewLine -> (paddedNoSpecBase :) . wrapRest columns listPadding'+ WithModuleName -> wrap columns paddedBase (withModuleNameBaseLength + 4)+ WithAlias -> wrap columns paddedBase (inlineBaseLength + 1) -- Add 1 extra space to ensure same padding as in original code.- AfterAlias -> withTail ((' ' : maybeSpace) ++)+ AfterAlias -> withTail ((' ' : maybeSpace) ++) . wrap columns paddedBase (afterAliasBaseLength + 1) inlineWithBreakWrap = paddedNoSpecBase : wrapRest columns listPadding'@@ -348,6 +350,8 @@ inlineBaseLength = length $ base' (padImport $ compoundImportName imp) [] []++ withModuleNameBaseLength = length $ base' "" [] [] afterAliasBaseLength = length $ base' (padImport $ compoundImportName imp) ["as " ++ as | H.ModuleName _ as <- maybeToList $ H.importAs imp] []
lib/Language/Haskell/Stylish/Step/TrailingWhitespace.hs view
@@ -19,4 +19,9 @@ -------------------------------------------------------------------------------- step :: Step-step = makeStep "TrailingWhitespace" $ \ls _ -> map dropTrailingWhitespace ls+step = makeStep "TrailingWhitespace" $ \ls _ -> map dropTrailingWhitespace' ls+ where+ dropTrailingWhitespace' l = case l of+ -- Preserve page breaks+ "\12" -> l+ _ -> dropTrailingWhitespace l
stylish-haskell.cabal view
@@ -1,5 +1,5 @@ Name: stylish-haskell-Version: 0.9.2.2+Version: 0.9.3.0 Synopsis: Haskell code prettifier Homepage: https://github.com/jaspervdj/stylish-haskell License: BSD3@@ -70,7 +70,7 @@ Build-depends: stylish-haskell, strict >= 0.3 && < 0.4,- optparse-applicative >= 0.12 && < 0.15,+ optparse-applicative >= 0.12 && < 0.16, -- Copied from regular dependencies... aeson >= 0.6 && < 1.5, base >= 4.8 && < 5,
tests/Language/Haskell/Stylish/Step/Imports/Tests.hs view
@@ -32,11 +32,15 @@ , testCase "case 06" case06 , testCase "case 07" case07 , testCase "case 08" case08+ , testCase "case 08b" case08b , testCase "case 09" case09 , testCase "case 10" case10 , testCase "case 11" case11+ , testCase "case 11b" case11b , testCase "case 12" case12+ , testCase "case 12b" case12b , testCase "case 13" case13+ , testCase "case 13b" case13b , testCase "case 14" case14 , testCase "case 15" case15 , testCase "case 16" case16@@ -50,6 +54,7 @@ , testCase "case 21" case21 , testCase "case 22" case22 , testCase "case 23" case23+ , testCase "case 23b" case23b , testCase "case 24" case24 , testCase "case 25" case25 , testCase "case 26 (issue 185)" case26@@ -213,6 +218,28 @@ --------------------------------------------------------------------------------+case08b :: Assertion+case08b = expected+ @=? testStep (step 80 $ Options Global WithModuleName True Inline Inherit (LPConstant 4) True False) input+ where+ expected = unlines+ ["module Herp where"+ , ""+ , "import Control.Monad"+ , "import Data.List as List (concat, foldl, foldr, head, init,"+ , " last, length, map, null, reverse, tail, (++))"+ , "import Data.Map (Map, insert, lookup, (!))"+ , "import qualified Data.Map as M"+ , "import Only.Instances ()"+ , ""+ , "import Foo (Bar (..))"+ , "import Herp.Derp.Internals hiding (foo)"+ , ""+ , "herp = putStrLn \"import Hello world\""+ ]+++-------------------------------------------------------------------------------- case09 :: Assertion case09 = expected @=? testStep (step 80 $ Options Global WithAlias True Multiline Inherit (LPConstant 4) True False) input@@ -313,6 +340,27 @@ ] +case11b :: Assertion+case11b = expected+ @=? testStep (step 80 $ Options Group WithModuleName True Inline Inherit (LPConstant 4) True False) input+ where+ expected = unlines+ [ "module Herp where"+ , ""+ , "import Control.Monad"+ , "import Data.List as List (concat, foldl, foldr, head, init, last,"+ , " length, map, null, reverse, tail, (++))"+ , "import Data.Map (Map, insert, lookup, (!))"+ , "import qualified Data.Map as M"+ , "import Only.Instances ()"+ , ""+ , "import Foo (Bar (..))"+ , "import Herp.Derp.Internals hiding (foo)"+ , ""+ , "herp = putStrLn \"import Hello world\""+ ]++ -------------------------------------------------------------------------------- case12 :: Assertion case12 = expected@@ -329,6 +377,18 @@ --------------------------------------------------------------------------------+case12b :: Assertion+case12b = expected+ @=? testStep (step 80 $ Options Group WithModuleName True Inline Inherit (LPConstant 2) True False) input'+ where+ input' = unlines+ [ "import Data.List (map)"+ ]++ expected = input'+++-------------------------------------------------------------------------------- case13 :: Assertion case13 = expected @=? testStep (step 80 $ Options None WithAlias True InlineWithBreak Inherit (LPConstant 4) True False) input'@@ -346,6 +406,23 @@ --------------------------------------------------------------------------------+case13b :: Assertion+case13b = expected+ @=? testStep (step 80 $ Options None WithModuleName True InlineWithBreak Inherit (LPConstant 4) True False) input'+ where+ input' = unlines+ [ "import qualified Data.List as List (concat, foldl, foldr, head, init,"+ , " last, length, map, null, reverse, tail, (++))"+ ]++ expected = unlines+ [ "import qualified Data.List as List"+ , " (concat, foldl, foldr, head, init, last, length, map, null, reverse, tail,"+ , " (++))"+ ]+++-------------------------------------------------------------------------------- case14 :: Assertion case14 = expected @=? testStep@@ -451,6 +528,7 @@ , "import Data.Acid as Acid (closeAcidState, createCheckpoint, openLocalStateFrom)" ] + -------------------------------------------------------------------------------- case19 :: Assertion case19 = expected @=? testStep@@ -467,6 +545,7 @@ , " intersperse)" ] + case19b :: Assertion case19b = expected @=? testStep (step 40 $ Options File NewLine True InlineWithBreak RightAfter (LPConstant 17) True False) case19input@@ -482,6 +561,7 @@ , " intersperse)" ] + case19c :: Assertion case19c = expected @=? testStep (step 40 $ Options File NewLine True InlineWithBreak RightAfter LPModuleName True False) case19input@@ -497,6 +577,7 @@ , " intersperse)" ] + case19d :: Assertion case19d = expected @=? testStep (step 40 $ Options Global NewLine True InlineWithBreak RightAfter LPModuleName True False) case19input@@ -512,6 +593,7 @@ , " intersperse)" ] + case19input :: String case19input = unlines [ "import Prelude.Compat hiding (foldMap)"@@ -520,6 +602,7 @@ , "import Data.List (foldl', intercalate, intersperse)" ] + -------------------------------------------------------------------------------- case20 :: Assertion case20 = expected@@ -538,6 +621,7 @@ , "import Data.Set (empty)" ] + -------------------------------------------------------------------------------- case21 :: Assertion case21 = expected@@ -568,6 +652,7 @@ , "import X9 hiding (x, y, z, x)" ] + -------------------------------------------------------------------------------- case22 :: Assertion case22 = expected@@ -594,6 +679,7 @@ "theLongestNameYet, shortName)" ] + -------------------------------------------------------------------------------- case23 :: Assertion case23 = expected@@ -618,7 +704,34 @@ , "import Data.ALongName.Foo (Foo, Goo, Boo)" ] + --------------------------------------------------------------------------------+case23b :: Assertion+case23b = expected+ @=? testStep (step 40 $ Options None WithModuleName 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'@@ -640,6 +753,7 @@ , "import Data.ALongName.Foo (FooReallyLong, " ++ "GooReallyLong, BooReallyLong)" ]+ -------------------------------------------------------------------------------- case25 :: Assertion
tests/Language/Haskell/Stylish/Step/TrailingWhitespace/Tests.hs view
@@ -28,12 +28,16 @@ where input = unlines [ "module Main where"- , " "+ , " \t" , "data Foo = Bar | Qux\t "+ , "\12" -- page break+ , " \12" -- malformed page break ] expected = unlines [ "module Main where" , "" , "data Foo = Bar | Qux"+ , "\12" -- page break+ , "" ]