mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Begin moving away from ParseResponse
This commit is contained in:
parent
e006b9c2dd
commit
3f402120d9
@ -4,7 +4,7 @@ import Options.Applicative
|
||||
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Unused.Parser (parseLines)
|
||||
import Unused.Types (ParseResponse, RemovalLikelihood(..))
|
||||
import Unused.Types (TermMatchSet, RemovalLikelihood(..))
|
||||
import Unused.ResultsClassifier
|
||||
import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths)
|
||||
import Unused.Grouping (CurrentGrouping(..), groupedResponses)
|
||||
@ -54,7 +54,7 @@ run options = withoutCursor $ do
|
||||
resetScreen
|
||||
|
||||
either printParseError (printSearchResults . groupedResponses (oGrouping options)) $
|
||||
optionFilters options response
|
||||
fmap (optionFilters options) response
|
||||
|
||||
return ()
|
||||
|
||||
@ -73,7 +73,7 @@ withInfo :: Parser a -> String -> String -> String -> ParserInfo a
|
||||
withInfo opts h d f =
|
||||
info (helper <*> opts) $ header h <> progDesc d <> footer f
|
||||
|
||||
optionFilters :: Options -> (ParseResponse -> ParseResponse)
|
||||
optionFilters :: Options -> (TermMatchSet -> TermMatchSet)
|
||||
optionFilters o =
|
||||
foldl1 (.) filters
|
||||
where
|
||||
|
@ -14,19 +14,19 @@ import Unused.Regex (matchRegex)
|
||||
import Unused.Types
|
||||
import Unused.ResultsClassifier
|
||||
|
||||
withOneOccurrence :: ParseResponse -> ParseResponse
|
||||
withOneOccurrence = applyFilter (const oneOccurence)
|
||||
withOneOccurrence :: TermMatchSet -> TermMatchSet
|
||||
withOneOccurrence = Map.filterWithKey (const oneOccurence)
|
||||
|
||||
oneOccurence :: TermResults -> Bool
|
||||
oneOccurence = (== 1) . totalOccurrenceCount
|
||||
|
||||
withLikelihoods :: [RemovalLikelihood] -> ParseResponse -> ParseResponse
|
||||
withLikelihoods :: [RemovalLikelihood] -> TermMatchSet -> TermMatchSet
|
||||
withLikelihoods [] = id
|
||||
withLikelihoods l = applyFilter (const $ includesLikelihood l)
|
||||
withLikelihoods l = Map.filterWithKey (const $ includesLikelihood l)
|
||||
|
||||
ignoringPaths :: [String] -> ParseResponse -> ParseResponse
|
||||
ignoringPaths :: [String] -> TermMatchSet -> TermMatchSet
|
||||
ignoringPaths xs =
|
||||
fmap (updateMatches newMatches)
|
||||
updateMatches newMatches
|
||||
where
|
||||
newMatches = filter (not . matchesPath . tmPath)
|
||||
matchesPath p = any (`isInfixOf` p) xs
|
||||
@ -71,8 +71,5 @@ updateMatches fm =
|
||||
where
|
||||
updateMatchesWith f tr = tr { trMatches = f tr }
|
||||
|
||||
applyFilter :: (String -> TermResults -> Bool) -> ParseResponse -> ParseResponse
|
||||
applyFilter = fmap . Map.filterWithKey
|
||||
|
||||
isAllowedTerm :: TermResults -> [String] -> Bool
|
||||
isAllowedTerm = elem . trTerm
|
||||
|
Loading…
Reference in New Issue
Block a user