mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Ignore file and directory patterns
This commit is contained in:
parent
ee1c4cd0f6
commit
ba8159f08d
11
app/Main.hs
11
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"
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user