diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index b9305c0..2dfeafa 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -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 = diff --git a/test/Unused/ResponseFilterSpec.hs b/test/Unused/ResponseFilterSpec.hs index 92b7731..138c529 100644 --- a/test/Unused/ResponseFilterSpec.hs +++ b/test/Unused/ResponseFilterSpec.hs @@ -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