mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-08-15 15:50:26 +03:00
Initial Haskell support for allowed tokens
This is based off of tags generated by Hasktags: https://hackage.haskell.org/package/hasktags
This commit is contained in:
parent
bcbc1b6462
commit
3851c98d59
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user