hs-inspector 0.3.0.0 → 0.4.0.0
raw patch · 4 files changed
+49/−13 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Language.Haskell.Inspector.Smell: isBooleanLiteral :: HsExp -> Bool
+ Language.Haskell.Detector: detect :: Inspection -> Code -> [Binding]
+ Language.Haskell.Inspector: bindingInMatch :: HsMatch -> String
+ Language.Haskell.Inspector: hasTypeDeclaration :: Inspection
+ Language.Haskell.Inspector: hasTypeSignature :: Inspection
+ Language.Haskell.Inspector: isName :: String -> HsName -> Bool
+ Language.Haskell.Inspector: nameOf :: HsName -> String
+ Language.Haskell.Inspector: negateInspection :: Inspection -> Inspection
+ Language.Haskell.Inspector: orNil :: Maybe [t] -> [t]
Files
- hs-inspector.cabal +3/−2
- src/Language/Haskell/Detector.hs +16/−0
- src/Language/Haskell/Inspector.hs +25/−10
- src/Language/Haskell/Inspector/Smell.hs +5/−1
hs-inspector.cabal view
@@ -2,7 +2,7 @@ -- http://haskell.org/cabal/users-guide/ name: hs-inspector-version: 0.3.0.0+version: 0.4.0.0 license: MIT license-file: LICENSE author: Franco Leonardo Bulgarelli@@ -21,9 +21,10 @@ hs-source-dirs: src exposed-modules:- Language.Haskell.Inspector.Smell Language.Haskell.Explorer+ Language.Haskell.Detector Language.Haskell.Inspector+ Language.Haskell.Inspector.Smell build-depends: base >= 4 && < 5, haskell-src >= 1 && < 1.1
+ src/Language/Haskell/Detector.hs view
@@ -0,0 +1,16 @@+module Language.Haskell.Detector (detect) where++import Language.Haskell.Inspector+import Language.Haskell.Syntax++bindingsOf :: Code -> [String]+bindingsOf = orNil . withCode (concatMap bindings)+ where+ bindings (HsTypeSig _ [b] _) = [nameOf b]+ bindings (HsTypeDecl _ b _ _) = [nameOf b]+ bindings (HsPatBind _ (HsPVar n) _ _) = [nameOf n]+ bindings (HsFunBind cases) = map bindingInMatch cases+ bindings _ = []++detect :: Inspection -> Code -> [Binding]+detect inspection code = filter (`inspection` code) $ bindingsOf code
src/Language/Haskell/Inspector.hs view
@@ -57,13 +57,10 @@ f (E (HsVar name)) = isTarget name f _ = False - isTarget (Qual _ n) = isTarget' n- isTarget (UnQual n) = isTarget' n+ isTarget (Qual _ n) = isName target n+ isTarget (UnQual n) = isName target n isTarget _ = False - isTarget' (HsSymbol t) = t == target- isTarget' (HsIdent t) = t == target- -- | Inspection that tells whether a binding uses lists comprehensions -- in its definition hasComprehension :: Inspection@@ -75,11 +72,31 @@ hasBinding :: Inspection hasBinding binding = isJust . findBindingRhs binding +hasTypeDeclaration :: Inspection+hasTypeDeclaration binding = testWithCode (any f)+ where f (HsTypeDecl _ hsName _ _) = isName binding hsName+ f _ = False++hasTypeSignature :: Inspection+hasTypeSignature binding = testWithCode (any f)+ where f (HsTypeSig _ [hsName] _) = isName binding hsName+ f _ = False+ isParseable :: Code -> Bool isParseable = testWithCode (const True) +negateInspection :: Inspection -> Inspection+negateInspection f code = not . f code+ -- =================================================== +isName name hsName = nameOf hsName == name++nameOf (HsSymbol n) = n+nameOf (HsIdent n) = n++bindingInMatch (HsMatch _ n _ _ _) = nameOf n+ isBindingEO f = isBindingRhs isExpr where isExpr rhs = exploreExprs f $ topExprs rhs @@ -92,13 +109,10 @@ withBindingRhs f binding = fmap f . findBindingRhs binding findBindingRhs binding = fmap rhsForBinding . join . withCode (find isBinding)- where isBinding (HsPatBind _ (HsPVar (HsIdent name)) _ _) = name == binding- isBinding (HsFunBind cases) = any isBindingInMatch cases+ where isBinding (HsPatBind _ (HsPVar n) _ _) = nameOf n == binding+ isBinding (HsFunBind cases) = any ((== binding).bindingInMatch) cases isBinding _ = False - isBindingInMatch (HsMatch _ (HsIdent name) _ _ _ ) = name == binding- isBindingInMatch _ = False- rhsForBinding :: HsDecl -> [HsRhs] rhsForBinding (HsPatBind _ _ rhs localDecls) = concatRhs rhs localDecls rhsForBinding (HsFunBind cases) = cases >>= \(HsMatch _ _ _ rhs localDecls) -> concatRhs rhs localDecls@@ -113,4 +127,5 @@ | otherwise = Nothing orFalse = fromMaybe False+orNil = fromMaybe []
src/Language/Haskell/Inspector/Smell.hs view
@@ -1,4 +1,8 @@-module Language.Haskell.Inspector.Smell where+module Language.Haskell.Inspector.Smell (+ hasRedundantBooleanComparison,+ hasRedundantIf,+ hasRedundantGuards,+ hasRedundantLambda) where import Language.Haskell.Explorer import Language.Haskell.Syntax