packages feed

stylish-haskell 0.5.13.0 → 0.5.14.0

raw patch · 4 files changed

+51/−24 lines, 4 filesdep ~sybPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: syb

API changes (from Hackage documentation)

Files

CHANGELOG view
@@ -1,3 +1,7 @@+- 0.5.14.0+    * Bump `syb` to 0.5+    * Slight refactoring in align code+ - 0.5.13.0     * Fix issue with shebang code 
src/Language/Haskell/Stylish/Step/Records.hs view
@@ -17,9 +17,9 @@   ---------------------------------------------------------------------------------records :: H.Module l -> [[H.FieldDecl l]]+records :: H.Module l -> [[Alignable l]] records modu =-    [ fields+    [ map fieldDeclToAlignable fields     | H.Module _ _ _ _ decls                     <- [modu]     , H.DataDecl _ _ _ _ cons _                  <- decls     , H.QualConDecl _ _ _ (H.RecDecl _ _ fields) <- cons@@ -27,14 +27,32 @@   --------------------------------------------------------------------------------+data Alignable a = Alignable+    { aContainer :: !a+    , aLeft      :: !a+    , aRight     :: !a+    } deriving (Show)+++--------------------------------------------------------------------------------+fieldDeclToAlignable :: H.FieldDecl a -> Alignable a+fieldDeclToAlignable (H.FieldDecl ann names ty) = Alignable+    { aContainer = ann+    , aLeft      = H.ann (last names)+    , aRight     = H.ann ty+    }+++-------------------------------------------------------------------------------- -- | Align the type of a field-align :: [(Int, Int)] -> [Change String]+align :: [Alignable H.SrcSpan] -> [Change String] align alignment = map align' alignment   where-    longest = maximum $ map snd alignment+    longest = maximum $ map (H.srcSpanEndColumn . aLeft) alignment -    align' (line, column) = changeLine line $ \str ->-        let (pre, post) = splitAt column str+    align' a = changeLine (H.srcSpanStartLine $ aContainer a) $ \str ->+        let column      = H.srcSpanEndColumn $ aLeft a+            (pre, post) = splitAt column str         in [padRight longest (trimRight pre) ++ trimLeft post]      trimLeft  = dropWhile isSpace@@ -42,23 +60,13 @@   ----------------------------------------------------------------------------------- | Determine alignment of fields-fieldAlignment :: [H.FieldDecl H.SrcSpan] -> [(Int, Int)]-fieldAlignment fields =-    [ (H.srcSpanStartLine ann, H.srcSpanEndColumn ann)-    | H.FieldDecl _ names _ <- fields-    , let ann = H.ann (last names)-    ]----------------------------------------------------------------------------------- -- | Checks that all no field of the record appears on more than one line, -- amonst other things-fixable :: [H.FieldDecl H.SrcSpan] -> Bool+fixable :: [Alignable H.SrcSpan] -> Bool fixable []     = False-fixable fields = all singleLine srcSpans && nonOverlapping srcSpans+fixable fields = all singleLine containers && nonOverlapping containers   where-    srcSpans          = map H.ann fields+    containers        = map aContainer fields     singleLine s      = H.srcSpanStartLine s == H.srcSpanEndLine s     nonOverlapping ss = length ss == length (nub $ map H.srcSpanStartLine ss) @@ -68,4 +76,4 @@ step = makeStep "Records" $ \ls (module', _) ->     let module''       = fmap H.srcInfoSpan module'         fixableRecords = filter fixable $ records module''-    in applyChanges (fixableRecords >>= align . fieldAlignment) ls+    in applyChanges (fixableRecords >>= align) ls
stylish-haskell.cabal view
@@ -1,5 +1,5 @@ Name:          stylish-haskell-Version:       0.5.13.0+Version:       0.5.14.0 Synopsis:      Haskell code prettifier Homepage:      https://github.com/jaspervdj/stylish-haskell License:       BSD3@@ -54,7 +54,7 @@     filepath         >= 1.1  && < 1.5,     haskell-src-exts >= 1.16 && < 1.17,     mtl              >= 2.0  && < 2.3,-    syb              >= 0.3  && < 0.5,+    syb              >= 0.3  && < 0.6,     yaml             >= 0.7  && < 0.9  Executable stylish-haskell@@ -75,7 +75,7 @@     filepath         >= 1.1  && < 1.5,     haskell-src-exts >= 1.16 && < 1.17,     mtl              >= 2.0  && < 2.3,-    syb              >= 0.3  && < 0.5,+    syb              >= 0.3  && < 0.6,     yaml             >= 0.7  && < 0.9  Test-suite stylish-haskell-tests@@ -108,7 +108,7 @@     filepath         >= 1.1  && < 1.5,     haskell-src-exts >= 1.16 && < 1.17,     mtl              >= 2.0  && < 2.3,-    syb              >= 0.3  && < 0.5,+    syb              >= 0.3  && < 0.6,     yaml             >= 0.7  && < 0.9  Source-repository head
tests/Language/Haskell/Stylish/Step/Records/Tests.hs view
@@ -19,6 +19,7 @@ tests :: Test tests = testGroup "Language.Haskell.Stylish.Step.Records.Tests"     [ testCase "case 01" case01+    , testCase "case 02" case02     ]  @@ -37,5 +38,19 @@         [ "data Foo = Foo"         , "    { foo    :: Int"         , "    , barqux :: String"+        , "    } deriving (Show)"+        ]+++--------------------------------------------------------------------------------+case02 :: Assertion+case02 = input @=? testStep step input+  where+    -- Don't attempt to align this since a field spans multiple lines+    input = unlines+        [ "data Foo = Foo"+        , "    { foo :: Int"+        , "    , barqux"+        , "         :: String"         , "    } deriving (Show)"         ]