pinned-warnings 0.1.0.5 → 0.1.0.6
raw patch · 3 files changed
+46/−3 lines, 3 files
Files
- pinned-warnings.cabal +1/−1
- src/Internal/FixWarnings.hs +15/−2
- test/Spec.hs +30/−0
pinned-warnings.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: pinned-warnings-version: 0.1.0.5+version: 0.1.0.6 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
@@ -13,6 +13,7 @@ import Data.Bifunctor (first) import qualified Data.ByteString.Char8 as BS import Data.Char (isSpace)+import Data.Maybe (isJust) import Data.Monoid (Alt(..)) import qualified Data.Map.Strict as M import qualified System.Directory as Dir@@ -37,6 +38,7 @@ mCached <- gets (M.lookup file) + -- Get the src lines from the cache or read it from the file srcLines <- maybe (liftIO . fmap BS.lines $ BS.readFile file) pure@@ -105,9 +107,19 @@ (stmt'', after') = splitAtImportEnd $ stmt' <> after + hasExplicitList+ -- Check the next line to see if contains an explicit import list+ | a : _ <- after+ , BS.length (BS.takeWhile isSpace a)+ > BS.length (BS.takeWhile isSpace stmt)+ , BS.take 1 (BS.dropSpace a) == "("+ = True+ | otherwise = isJust (BS.elemIndex '(' stmt)+ in case warn of- WholeModule ->- Just $ before <> after+ WholeModule+ | hasExplicitList -> Just $ before <> after'+ | otherwise -> Just $ before <> after IndividualThings things -> (<> after') . (before' <>) . BS.lines <$>@@ -178,6 +190,7 @@ 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
test/Spec.hs view
@@ -45,6 +45,15 @@ fixRedundancyWarning 1 (IndividualThings [":~:"]) [input11] @?= Just [output11]++ fixRedundancyWarning 1 WholeModule input13+ @?= Just output13++ fixRedundancyWarning 1 WholeModule input14+ @?= Just output14++ fixRedundancyWarning 1 WholeModule input15+ @?= Just output15 ] input1, output1 :: BS.ByteString@@ -116,3 +125,24 @@ input12, output12 :: BS.ByteString input12 = "import Foo (foo, (:~:)(one, two), baz)" output12 = "import Foo (foo, (:~:)(one), baz)"++input13, output13 :: [BS.ByteString]+input13 = [ "import Foo"+ , " (one, two, three)"+ , "import Bar"+ ]+output13 = [ "import Bar" ]++input14, output14 :: [BS.ByteString]+input14 = [ "import Foo (one"+ , " ,two"+ , " )"+ , "import Bar"+ ]+output14 = [ "import Bar" ]++input15, output15 :: [BS.ByteString]+input15 = [ "import Foo"+ , "import Bar"+ ]+output15 = [ "import Bar" ]