mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-10-26 05:07:35 +03:00
Allow multiple matches with single-occurring appropriate tokens
This commit is contained in:
parent
f7a2e1a287
commit
3b627ee1c3
@ -47,25 +47,21 @@ isClassOrModule = matchRegex "^[A-Z]" . trTerm
|
||||
|
||||
railsSingleOkay :: TermResults -> Bool
|
||||
railsSingleOkay r =
|
||||
and [isClassOrModule r, oneFile r, oneOccurence r, controller || helper || migration]
|
||||
isClassOrModule r && (controller || helper || migration)
|
||||
where
|
||||
controller = matchRegex "^app/controllers/" singlePath && matchRegex "Controller$" (trTerm r)
|
||||
helper = matchRegex "^app/helpers/" singlePath && matchRegex "Helper$" (trTerm r)
|
||||
migration = matchRegex "^db/migrate/" singlePath
|
||||
singlePath = path $ tmPath <$> trMatches r
|
||||
path (x:_) = x
|
||||
path [] = ""
|
||||
controller = any (matchRegex "^app/controllers/") paths && matchRegex "Controller$" (trTerm r)
|
||||
helper = any (matchRegex "^app/helpers/") paths && matchRegex "Helper$" (trTerm r)
|
||||
migration = any (matchRegex "^db/migrate/") paths
|
||||
paths = tmPath <$> trMatches r
|
||||
|
||||
elixirSingleOkay :: TermResults -> Bool
|
||||
elixirSingleOkay r =
|
||||
and [isClassOrModule r, oneFile r, oneOccurence r, view || test || migration]
|
||||
isClassOrModule r && (view || test || migration)
|
||||
where
|
||||
migration = matchRegex "^priv/repo/migrations/" singlePath
|
||||
view = matchRegex "^web/views/" singlePath && matchRegex "View$" (trTerm r)
|
||||
test = matchRegex "^test/" singlePath && matchRegex "Test$" (trTerm r)
|
||||
singlePath = path $ tmPath <$> trMatches r
|
||||
path (x:_) = x
|
||||
path [] = ""
|
||||
migration = any (matchRegex "^priv/repo/migrations/") paths
|
||||
view = any (matchRegex "^web/views/") paths && matchRegex "View$" (trTerm r)
|
||||
test = any (matchRegex "^test/") paths && matchRegex "Test$" (trTerm r)
|
||||
paths = tmPath <$> trMatches r
|
||||
|
||||
updateMatches :: ([TermMatch] -> [TermMatch]) -> TermMatchSet -> TermMatchSet
|
||||
updateMatches fm =
|
||||
|
@ -40,6 +40,13 @@ spec = parallel $ do
|
||||
|
||||
railsSingleOkay result `shouldBe` False
|
||||
|
||||
it "allows matches intermixed with other results" $ do
|
||||
let appToken = TermMatch "ApplicationHelper" "app/helpers/application_helper.rb" 1
|
||||
let testToken = TermMatch "ApplicationHelper" "spec/helpers/application_helper_spec.rb" 10
|
||||
let result = resultsFromMatches [appToken, testToken]
|
||||
|
||||
railsSingleOkay result `shouldBe` True
|
||||
|
||||
describe "elixirSingleOkay" $ do
|
||||
it "disallows controllers" $ do
|
||||
let match = TermMatch "PageController" "web/controllers/page_controller.rb" 1
|
||||
@ -77,3 +84,10 @@ spec = parallel $ do
|
||||
let result = resultsFromMatches [match]
|
||||
|
||||
elixirSingleOkay result `shouldBe` False
|
||||
|
||||
it "allows matches intermixed with other results" $ do
|
||||
let appToken = TermMatch "UserView" "web/views/user_view.ex" 1
|
||||
let testToken = TermMatch "UserView" "test/views/user_view_test.exs" 10
|
||||
let result = resultsFromMatches [appToken, testToken]
|
||||
|
||||
elixirSingleOkay result `shouldBe` True
|
||||
|
Loading…
Reference in New Issue
Block a user