diff --git a/src/Unused/LikelihoodCalculator.hs b/src/Unused/LikelihoodCalculator.hs index ff35983..7049b03 100644 --- a/src/Unused/LikelihoodCalculator.hs +++ b/src/Unused/LikelihoodCalculator.hs @@ -3,7 +3,7 @@ module Unused.LikelihoodCalculator ) where import Unused.Types -import Unused.ResponseFilter (railsSingleOkay, elixirSingleOkay) +import Unused.ResponseFilter (railsSingleOkay, elixirSingleOkay, haskellSingleOkay) calculateLikelihood :: TermResults -> TermResults calculateLikelihood r = @@ -14,6 +14,7 @@ calculateLikelihood r = newLikelihood | railsSingleOkay r = (Low, "a class, module, or migration that often occurs in only one file") | elixirSingleOkay r = (Low, "a class, module, or migration that often occurs in only one file") + | haskellSingleOkay r = (Low, "a module, function, or special case that often occurs in only one file") | singleNonTestUsage r && testsExist r = (High, "only the definition and corresponding tests exist") | doubleNonTestUsage r && testsExist r = (Medium, "only the definition and one other use, along with tests, exists") | totalScore < 2 = (High, "used once") diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index 9ff58e0..1d35fc7 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -6,6 +6,7 @@ module Unused.ResponseFilter , isClassOrModule , railsSingleOkay , elixirSingleOkay + , haskellSingleOkay , updateMatches ) where @@ -57,6 +58,14 @@ elixirSingleOkay r = allowedTerms = ["Mixfile", "__using__"] paths = tmPath <$> trMatches r +haskellSingleOkay :: TermResults -> Bool +haskellSingleOkay r = + isAllowedTerm r allowedTerms || cabalFile + where + allowedTerms = ["instance"] + cabalFile = any (matchRegex "^*.cabal$") paths + paths = tmPath <$> trMatches r + updateMatches :: ([TermMatch] -> [TermMatch]) -> TermMatchSet -> TermMatchSet updateMatches fm = Map.map (updateMatchesWith $ fm . trMatches) diff --git a/test/Unused/ResponseFilterSpec.hs b/test/Unused/ResponseFilterSpec.hs index 17b5049..7d16330 100644 --- a/test/Unused/ResponseFilterSpec.hs +++ b/test/Unused/ResponseFilterSpec.hs @@ -102,3 +102,16 @@ spec = parallel $ do let result = resultsFromMatches [appToken, testToken] elixirSingleOkay result `shouldBe` True + + describe "haskellSingleOkay" $ do + it "allows instance" $ do + let match = TermMatch "instance" "src/Lib/Types.hs" 1 + let result = resultsFromMatches [match] + + haskellSingleOkay result `shouldBe` True + + it "allows items in the *.cabal file" $ do + let match = TermMatch "Lib.SomethingSpec" "lib.cabal" 1 + let result = resultsFromMatches [match] + + haskellSingleOkay result `shouldBe` True