diff --git a/app/Main.hs b/app/Main.hs index 82cec2f..6fe389f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -4,13 +4,14 @@ import Options.Applicative import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout) import Unused.Parser (parseLines) import Unused.Types (ParseResponse, RemovalLikelihood(..)) -import Unused.ResponseFilter (withOneOccurrence, withOneFile, withLikelihoods) +import Unused.ResponseFilter (withOneOccurrence, withOneFile, withLikelihoods, ignoringPaths) import Unused.CLI (SearchRunner(..), executeSearch, printParseError, printSearchResults, resetScreen) data Options = Options { oSearchRunner :: SearchRunner , oAllOccurrencesAndFiles :: Bool , oLikelihoods :: [RemovalLikelihood] + , oIgnoredPaths :: [String] } main :: IO () @@ -42,6 +43,7 @@ optionFilters o = filters = [ if oAllOccurrencesAndFiles o then id else withOneOccurrence . withOneFile , withLikelihoods $ oLikelihoods o + , ignoringPaths $ oIgnoredPaths o ] parseOptions :: Parser Options @@ -50,6 +52,7 @@ parseOptions = <$> parseSearchRunner <*> parseDisplayAllMatches <*> parseLikelihoods + <*> parseIgnorePaths parseSearchRunner :: Parser SearchRunner parseSearchRunner = @@ -79,3 +82,9 @@ parseLikelihoodOption = strOption $ short 'l' <> long "likelihood" <> help "[Allows multiple] [Allowed values: high, medium, low] Display results based on likelihood" + +parseIgnorePaths :: Parser [String] +parseIgnorePaths = many $ strOption $ + long "ignore" + <> metavar "PATH" + <> help "[Allows multiple] Ignore paths that contain PATH" diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index ffcd80e..b9305c0 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -4,6 +4,7 @@ module Unused.ResponseFilter , withLikelihoods , oneFile , oneOccurence + , ignoringPaths , isClassOrModule , railsSingleOkay , elixirSingleOkay @@ -11,6 +12,7 @@ module Unused.ResponseFilter ) where import qualified Data.Map.Strict as Map +import Data.List (isInfixOf) import Unused.Regex (matchRegex) import Unused.Types @@ -27,6 +29,13 @@ withLikelihoods :: [RemovalLikelihood] -> ParseResponse -> ParseResponse withLikelihoods [] = id withLikelihoods l = applyFilter (const $ includesLikelihood l) +ignoringPaths :: [String] -> ParseResponse -> ParseResponse +ignoringPaths xs = + fmap (updateMatches newMatches) + where + newMatches = filter (not . matchesPath . tmPath) + matchesPath p = any (`isInfixOf` p) xs + oneFile :: TermResults -> Bool oneFile = (== 1) . trTotalFiles