hlint 2.1.4 → 2.1.5
raw patch · 5 files changed
+32/−23 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.txt +3/−0
- hlint.cabal +1/−1
- src/HSE/Util.hs +0/−3
- src/Hint/Extensions.hs +27/−18
- src/Hint/Naming.hs +1/−1
CHANGES.txt view
@@ -1,5 +1,8 @@ Changelog for HLint (* = breaking change) +2.1.5, released 2018-05-05+ #478, take account of deriving strategies for extension use+ #477, don't warn about unit_ as tasty-discover recommends it 2.1.4, released 2018-05-01 Don't warn about redundant $ for a $ b{c=d} 2.1.3, released 2018-04-18
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.18 build-type: Simple name: hlint-version: 2.1.4+version: 2.1.5 license: BSD3 license-file: LICENSE category: Development
src/HSE/Util.hs view
@@ -85,9 +85,6 @@ fromTyBang (TyBang _ _ _ x) = x fromTyBang x = x -fromDeriving :: Deriving s -> [InstRule s]-fromDeriving (Deriving _ _ x) = x- -- is* :: Exp_ -> Bool -- is* :: Decl_ -> Bool isVar Var{} = True; isVar _ = False
src/Hint/Extensions.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE RecordWildCards #-} {- Suggest removal of unnecessary extensions i.e. They have {-# LANGUAGE RecursiveDo #-} but no mdo keywords@@ -113,6 +112,8 @@ main = 5.6# {-# LANGUAGE MagicHash #-} \ foo = id --+{-# LANGUAGE GeneralizedNewtypeDeriving #-} \+newtype X = X Int deriving newtype Show </TEST> -} @@ -159,21 +160,19 @@ deriveCategory = ["Functor","Foldable","Traversable"] -- | Classes that can't require newtype deriving-noGeneralizedNewtypeDeriving =+noDeriveNewtype = delete "Enum" deriveHaskell ++ -- Enum can't always be derived on a newtype deriveGenerics -- Generics stuff can't newtype derive since it has the ctor in it --- | Classes that can't require DeriveAnyClass-noDeriveAnyClass = deriveHaskell ++ deriveGenerics ++ deriveCategory+-- | Classes that can appear as stock, and can't appear as anyclass+deriveStock = deriveHaskell ++ deriveGenerics ++ deriveCategory usedExt :: Extension -> Module_ -> Bool usedExt (EnableExtension x) = used x usedExt (UnknownExtension "NumDecimals") = hasS isWholeFrac usedExt (UnknownExtension "DeriveLift") = hasDerive ["Lift"]-usedExt (UnknownExtension "DeriveAnyClass") =- any (`notElem` noDeriveAnyClass) .- (\Derives{..} -> derivesNewType ++ derivesData) . derives+usedExt (UnknownExtension "DeriveAnyClass") = not . null . derivesAnyclass . derives usedExt _ = const True @@ -213,9 +212,7 @@ used DeriveFoldable = hasDerive ["Foldable"] used DeriveTraversable = hasDerive ["Traversable"] used DeriveGeneric = hasDerive ["Generic","Generic1"]-used GeneralizedNewtypeDeriving =- any (`notElem` noGeneralizedNewtypeDeriving) .- (\Derives{..} -> derivesNewType ++ derivesStandalone) . derives+used GeneralizedNewtypeDeriving = not . null . derivesNewtype . derives used LambdaCase = hasS isLCase used TupleSections = hasS isTupleSection used OverloadedStrings = hasS isString@@ -238,14 +235,15 @@ hasDerive :: [String] -> Module_ -> Bool-hasDerive want m = any (`elem` want) $ derivesNewType ++ derivesData ++ derivesStandalone- where Derives{..} = derives m+hasDerive want = any (`elem` want) . derivesStock . derives +-- Derivations can be implemented using any one of 3 strategies, so for each derivation+-- add it to all the strategies that might plausibly implement it data Derives = Derives- {derivesNewType :: [String]- ,derivesData :: [String]- ,derivesStandalone :: [String]+ {derivesStock :: [String]+ ,derivesAnyclass :: [String]+ ,derivesNewtype :: [String] } instance Semigroup Derives where Derives x1 x2 x3 <> Derives y1 y2 y3 =@@ -254,6 +252,18 @@ mempty = Derives [] [] [] mappend = (<>) +addDerives :: Maybe (DataOrNew S) -> Maybe (DerivStrategy S) -> [String] -> Derives+addDerives _ (Just s) xs = case s of+ DerivStock{} -> mempty{derivesStock = xs}+ DerivAnyclass{} -> mempty{derivesAnyclass = xs}+ DerivNewtype{} -> mempty{derivesNewtype = xs}+addDerives nt _ xs = mempty+ {derivesStock = stock+ ,derivesAnyclass = other+ ,derivesNewtype = if maybe True isNewType nt then filter (`notElem` noDeriveNewtype) xs else []}+ where (stock, other) = partition (`elem` deriveStock) xs++ -- | What is derived on newtype, and on data type -- 'deriving' declarations may be on either, so we approximate as both newtype and data derives :: Module_ -> Derives@@ -269,11 +279,10 @@ decl (GDataDecl _ dn _ _ _ _ ds) = g dn ds decl (DataInsDecl _ dn _ _ ds) = g dn ds decl (GDataInsDecl _ dn _ _ _ ds) = g dn ds- decl (DerivDecl _ _ _ hd) = mempty{derivesStandalone=[ir hd]}+ decl (DerivDecl _ strategy _ hd) = addDerives Nothing strategy [ir hd] decl _ = mempty - g dn ds = if isNewType dn then mempty{derivesNewType=xs} else mempty{derivesData=xs}- where xs = concatMap (map ir . fromDeriving) ds+ g dn ds = mconcat [addDerives (Just dn) strategy $ map ir rules | Deriving _ strategy rules <- ds] ir (IRule _ _ _ x) = ih x ir (IParen _ x) = ir x
src/Hint/Naming.hs view
@@ -87,7 +87,7 @@ suggestName :: String -> Maybe String suggestName x | isSym x || good || not (any isLower x) || any isDigit x ||- any (`isPrefixOf` x) ["prop_","case_","test_"] = Nothing+ any (`isPrefixOf` x) ["prop_","case_","unit_","test_"] = Nothing | otherwise = Just $ f x where good = all isAlphaNum $ drp '_' $ drp '#' $ drp '\'' $ reverse $ drp '_' x