pinned-warnings 0.1.0.10 → 0.1.0.11
raw patch · 4 files changed
+77/−67 lines, 4 files
Files
- README.md +1/−1
- pinned-warnings.cabal +1/−1
- src/Internal/FixWarnings.hs +5/−9
- test/Spec.hs +70/−56
README.md view
@@ -44,6 +44,6 @@ ### Known limitations - Warnings that aren't for a specific module are not captured.-- Only the versions of GHC specified in the cabal file are supported (8.10, 9.0, 9.2)+- GHC versions less than 8.10.x are not supported. - If you make changes to files and call `showWarnings` without reloading first, the messages may not be referencing the right code anymore.
pinned-warnings.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: pinned-warnings-version: 0.1.0.10+version: 0.1.0.11 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
@@ -178,9 +178,7 @@ | otherwise = Nothing where- thingBS | isOperator bs = bs -- TODO there could be spaces in the parens- | otherwise = bs- where bs = BS.pack thing+ thingBS = BS.pack thing thingLen = BS.length thingBS -- A list of substring matches where each element is a pair of the prefix@@ -189,7 +187,7 @@ findCandidates inp = -- first isolate the portion that is within an open parens, otherwise -- if the module name is the same as the target then the search will fail.- let (beforeParen, inp') = BS.break (== '(') inp+ let (beforeParen, inp') = BS.break (\c -> c == '(' || c == ',') inp (pre, match) = BS.breakSubstring thingBS inp' in (beforeParen <> pre, match) : ( first ((beforeParen <> pre <> thingBS) <>)@@ -205,10 +203,6 @@ isSeparator = headPred $ \c -> isSpace c || c `elem` [',', '(', ')'] isCellStart = headPred $ \c -> isSpace c || c `elem` [',', '(']- isOperator = headPred (`elem` opChars)- where- opChars :: String- opChars = ":!#$%&*+./<=>?@\\^|-~" headPred :: (Char -> Bool) -> BS.ByteString -> Bool headPred p = maybe False (p . fst) . BS.uncons @@ -228,7 +222,9 @@ removeEnclosingParens startBS (BS.dropSpace -> endBS) | Just (')', end') <- BS.uncons endBS , Just (start', '(') <- BS.unsnoc $ BS.dropWhileEnd isSpace startBS- = (start', BS.dropSpace end')+ -- recurse because it could be an associated constructor that is an operator,+ -- i.e. NonEmpty((:|))+ = removeEnclosingParens start' end' | otherwise = (startBS, endBS) --------------------------------------------------------------------------------
test/Spec.hs view
@@ -13,65 +13,71 @@ tests = testGroup "FixWarnings" [ testCase "Removes thing" $ do--- fixRedundancyWarning 1 (IndividualThings ["foo"]) [input1]--- @?= Just [output1]--- --- fixRedundancyWarning 1 (IndividualThings ["bar"]) [input2]--- @?= Just [output2]--- --- fixRedundancyWarning 1 (IndividualThings ["baz", "foo"]) [input3]--- @?= Just [output3]--- --- fixRedundancyWarning 1 (IndividualThings ["bar"]) [input4]--- @?= Just [output4]--- --- fixRedundancyWarning 1 (IndividualThings ["foo", "baz"]) input5--- @?= Just output5--- --- fixRedundancyWarning 2 (IndividualThings ["bar"]) input6--- @?= Just output6--- --- fixRedundancyWarning 3 (IndividualThings ["bar"]) input7--- @?= Just output7--- --- fixRedundancyWarning 1 (IndividualThings ["Bar"]) [input8]--- @?= Just [output8]--- --- fixRedundancyWarning 1 (IndividualThings ["two"]) [input9]--- @?= Just [output9]--- --- fixRedundancyWarning 1 (IndividualThings ["+~"]) [input10]--- @?= Just [output10]--- --- fixRedundancyWarning 1 (IndividualThings [":~:"]) [input11]--- @?= Just [output11]--- --- fixRedundancyWarning 1 (IndividualThings ["two"]) [input12]--- @?= Just [output12]--- --- fixRedundancyWarning 1 WholeModule input13--- @?= Just output13--- --- fixRedundancyWarning 1 WholeModule input14--- @?= Just output14--- --- fixRedundancyWarning 1 WholeModule input15--- @?= Just output15--- --- fixRedundancyWarning 1 (IndividualThings ["zip", "zipWith"]) input16--- @?= Just output16--- --- fixRedundancyWarning 1 (IndividualThings ["Baz"]) input17--- @?= Just output17--- --- fixRedundancyWarning 1 (IndividualThings ["+"]) input18--- @?= Just output18--- --- fixRedundancyWarning 1 (IndividualThings [":+:"]) input19--- @?= Just output19+ fixRedundancyWarning 1 (IndividualThings ["foo"]) [input1]+ @?= Just [output1] + fixRedundancyWarning 1 (IndividualThings ["bar"]) [input2]+ @?= Just [output2]++ fixRedundancyWarning 1 (IndividualThings ["baz", "foo"]) [input3]+ @?= Just [output3]++ fixRedundancyWarning 1 (IndividualThings ["bar"]) [input4]+ @?= Just [output4]++ fixRedundancyWarning 1 (IndividualThings ["foo", "baz"]) input5+ @?= Just output5++ fixRedundancyWarning 2 (IndividualThings ["bar"]) input6+ @?= Just output6++ fixRedundancyWarning 3 (IndividualThings ["bar"]) input7+ @?= Just output7++ fixRedundancyWarning 1 (IndividualThings ["Bar"]) [input8]+ @?= Just [output8]++ fixRedundancyWarning 1 (IndividualThings ["two"]) [input9]+ @?= Just [output9]++ fixRedundancyWarning 1 (IndividualThings ["+~"]) [input10]+ @?= Just [output10]++ fixRedundancyWarning 1 (IndividualThings [":~:"]) [input11]+ @?= Just [output11]++ fixRedundancyWarning 1 (IndividualThings ["two"]) [input12]+ @?= Just [output12]++ fixRedundancyWarning 1 WholeModule input13+ @?= Just output13++ fixRedundancyWarning 1 WholeModule input14+ @?= Just output14++ fixRedundancyWarning 1 WholeModule input15+ @?= Just output15++ fixRedundancyWarning 1 (IndividualThings ["zip", "zipWith"]) input16+ @?= Just output16++ fixRedundancyWarning 1 (IndividualThings ["Baz"]) input17+ @?= Just output17++ fixRedundancyWarning 1 (IndividualThings ["+"]) input18+ @?= Just output18++ fixRedundancyWarning 1 (IndividualThings [":+:"]) input19+ @?= Just output19+ fixRedundancyWarning 1 (IndividualThings ["Foo"]) input20 @?= Just output20++ fixRedundancyWarning 1 (IndividualThings [":|"]) input21+ @?= Just output21++ fixRedundancyWarning 1 (IndividualThings ["zip"]) input22+ @?= Just output22 ] input1, output1 :: BS.ByteString@@ -185,3 +191,11 @@ input20, output20 :: [BS.ByteString] input20 = [ "import Foo (foo, Foo (.. ))" ] output20 = [ "import Foo (foo)" ]++input21, output21 :: [BS.ByteString]+input21 = [ "import Data.List.NonEmpty (NonEmpty((:|)), foo)" ]+output21 = [ "import Data.List.NonEmpty (NonEmpty, foo)" ]++input22, output22 :: [BS.ByteString]+input22 = [ "import Data.List (zipzip, zip)" ]+output22 = [ "import Data.List (zipzip)" ]