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 System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
||||||
import Unused.Parser (parseLines)
|
import Unused.Parser (parseLines)
|
||||||
import Unused.Types (ParseResponse, RemovalLikelihood(..))
|
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)
|
import Unused.CLI (SearchRunner(..), executeSearch, printParseError, printSearchResults, resetScreen)
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ oSearchRunner :: SearchRunner
|
{ oSearchRunner :: SearchRunner
|
||||||
, oAllOccurrencesAndFiles :: Bool
|
, oAllOccurrencesAndFiles :: Bool
|
||||||
, oLikelihoods :: [RemovalLikelihood]
|
, oLikelihoods :: [RemovalLikelihood]
|
||||||
|
, oIgnoredPaths :: [String]
|
||||||
}
|
}
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -42,6 +43,7 @@ optionFilters o =
|
|||||||
filters =
|
filters =
|
||||||
[ if oAllOccurrencesAndFiles o then id else withOneOccurrence . withOneFile
|
[ if oAllOccurrencesAndFiles o then id else withOneOccurrence . withOneFile
|
||||||
, withLikelihoods $ oLikelihoods o
|
, withLikelihoods $ oLikelihoods o
|
||||||
|
, ignoringPaths $ oIgnoredPaths o
|
||||||
]
|
]
|
||||||
|
|
||||||
parseOptions :: Parser Options
|
parseOptions :: Parser Options
|
||||||
@ -50,6 +52,7 @@ parseOptions =
|
|||||||
<$> parseSearchRunner
|
<$> parseSearchRunner
|
||||||
<*> parseDisplayAllMatches
|
<*> parseDisplayAllMatches
|
||||||
<*> parseLikelihoods
|
<*> parseLikelihoods
|
||||||
|
<*> parseIgnorePaths
|
||||||
|
|
||||||
parseSearchRunner :: Parser SearchRunner
|
parseSearchRunner :: Parser SearchRunner
|
||||||
parseSearchRunner =
|
parseSearchRunner =
|
||||||
@ -79,3 +82,9 @@ parseLikelihoodOption = strOption $
|
|||||||
short 'l'
|
short 'l'
|
||||||
<> long "likelihood"
|
<> long "likelihood"
|
||||||
<> help "[Allows multiple] [Allowed values: high, medium, low] Display results based on 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
|
, withLikelihoods
|
||||||
, oneFile
|
, oneFile
|
||||||
, oneOccurence
|
, oneOccurence
|
||||||
|
, ignoringPaths
|
||||||
, isClassOrModule
|
, isClassOrModule
|
||||||
, railsSingleOkay
|
, railsSingleOkay
|
||||||
, elixirSingleOkay
|
, elixirSingleOkay
|
||||||
@ -11,6 +12,7 @@ module Unused.ResponseFilter
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map.Strict as Map
|
import qualified Data.Map.Strict as Map
|
||||||
|
import Data.List (isInfixOf)
|
||||||
import Unused.Regex (matchRegex)
|
import Unused.Regex (matchRegex)
|
||||||
import Unused.Types
|
import Unused.Types
|
||||||
|
|
||||||
@ -27,6 +29,13 @@ withLikelihoods :: [RemovalLikelihood] -> ParseResponse -> ParseResponse
|
|||||||
withLikelihoods [] = id
|
withLikelihoods [] = id
|
||||||
withLikelihoods l = applyFilter (const $ includesLikelihood l)
|
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 :: TermResults -> Bool
|
||||||
oneFile = (== 1) . trTotalFiles
|
oneFile = (== 1) . trTotalFiles
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user