Allow multiple matches with single-occurring appropriate tokens

This commit is contained in:
Joshua Clayton 2016-05-08 22:25:48 -04:00
parent f7a2e1a287
commit 3b627ee1c3
2 changed files with 24 additions and 14 deletions

View File

@ -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 =

View File

@ -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