pinned-warnings 0.1.0.11 → 0.1.0.12
raw patch · 3 files changed
+46/−15 lines, 3 files
Files
- pinned-warnings.cabal +1/−1
- src/Internal/FixWarnings.hs +30/−14
- test/Spec.hs +15/−0
pinned-warnings.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: pinned-warnings-version: 0.1.0.11+version: 0.1.0.12 synopsis: Preserve warnings in a GHCi session description: Please see the README on GitHub at <https://github.com/aaronallen8455/pinned-warnings#readme> homepage: https://github.com/aaronallen8455/pinned-warnings#readme
src/Internal/FixWarnings.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE BangPatterns #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-}@@ -161,9 +162,10 @@ in s <> BS.takeWhile isSpace e end = BS.drop thingLen match- (start'', end') = dropRest <$> removeEnclosingParens start' end-- = BS.uncons end' >>= \case+ = do+ (start'', end') <- traverse removeAssociatedIds+ $ removeEnclosingParens start' end+ BS.uncons end' >>= \case -- Don't do this if the removed thing was an associated constructor (',', end'') | Just (_, e) <- BS.unsnoc $ BS.dropWhileEnd isSpace start''@@ -206,17 +208,6 @@ headPred :: (Char -> Bool) -> BS.ByteString -> Bool headPred p = maybe False (p . fst) . BS.uncons - -- Remove the portion to the right of the match up to the cell terminator- dropRest bs = case BS.uncons bs of- Nothing -> ""- -- Constructors of a type or methods of a class- Just (c, r)- | c == '(' -> BS.dropWhile (\x -> x /= ',' && x /= ')')- . BS.drop 1- $ BS.dropWhile (/= ')') r-- _ -> BS.dropSpace bs- -- If dealing with an operator, there will be enclosing parens with possible -- whitespace surrounding the operator. removeEnclosingParens startBS (BS.dropSpace -> endBS)@@ -226,6 +217,31 @@ -- i.e. NonEmpty((:|)) = removeEnclosingParens start' end' | otherwise = (startBS, endBS)++-- | Remove list of associated constructors of a type or methods of a class+-- and any space up until the next cell terminator.+removeAssociatedIds :: BS.ByteString -> Maybe BS.ByteString+removeAssociatedIds = checkForParens+ where+ checkForParens bs =+ let bs' = BS.dropSpace bs+ in case BS.uncons bs' of+ Nothing -> Just ""+ Just (c, r)+ | c == '(' -> removeParens 1 r+ _ -> Just bs'++ -- counts the depth of nested parens to handle the case of an operator+ -- appearing in the list.+ removeParens :: Int -> BS.ByteString -> Maybe BS.ByteString+ removeParens 0 bs = Just $ BS.dropSpace bs+ removeParens !n bs =+ let bs' = BS.dropWhile (\x -> x /= '(' && x /= ')') bs+ in case BS.uncons bs' of+ Just (c, r)+ | c == '(' -> removeParens (succ n) r+ | c == ')' -> removeParens (pred n) r+ _ -> Nothing -------------------------------------------------------------------------------- -- Parsing
test/Spec.hs view
@@ -40,6 +40,9 @@ fixRedundancyWarning 1 (IndividualThings ["two"]) [input9] @?= Just [output9] + fixRedundancyWarning 1 (IndividualThings ["one"]) [input9]+ @?= Just [output9a]+ fixRedundancyWarning 1 (IndividualThings ["+~"]) [input10] @?= Just [output10] @@ -78,6 +81,12 @@ fixRedundancyWarning 1 (IndividualThings ["zip"]) input22 @?= Just output22++ fixRedundancyWarning 1 (IndividualThings ["NonEmpty"]) input21+ @?= Just output21a++ fixRedundancyWarning 1 (IndividualThings [":|"]) input23+ @?= Just output23 ] input1, output1 :: BS.ByteString@@ -137,6 +146,7 @@ input9, output9 :: BS.ByteString input9 = "import Foo (foo, Bar(one, two), baz)" output9 = "import Foo (foo, Bar(one), baz)"+output9a = "import Foo (foo, Bar(two), baz)" input10, output10 :: BS.ByteString input10 = "import Foo (foo, (+~), baz)"@@ -195,7 +205,12 @@ input21, output21 :: [BS.ByteString] input21 = [ "import Data.List.NonEmpty (NonEmpty((:|)), foo)" ] output21 = [ "import Data.List.NonEmpty (NonEmpty, foo)" ]+output21a = [ "import Data.List.NonEmpty (foo)" ] input22, output22 :: [BS.ByteString] input22 = [ "import Data.List (zipzip, zip)" ] output22 = [ "import Data.List (zipzip)" ]++input23, output23 :: [BS.ByteString]+input23 = [ "import Data.List.NonEmpty (NonEmpty((:|), bar), foo)" ]+output23 = [ "import Data.List.NonEmpty (NonEmpty(bar), foo)" ]