Ignore file and directory patterns

This commit is contained in:
Joshua Clayton 2016-05-07 14:38:14 -04:00
parent ee1c4cd0f6
commit ba8159f08d
2 changed files with 19 additions and 1 deletions

View File

@ -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"

View File

@ -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