hlint 2.1.3 → 2.1.4
raw patch · 6 files changed
+25/−14 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.txt +2/−0
- README.md +1/−1
- hlint.cabal +1/−1
- src/HSE/Util.hs +2/−0
- src/Hint/Bracket.hs +18/−11
- src/Hint/Match.hs +1/−1
CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for HLint (* = breaking change) +2.1.4, released 2018-05-01+ Don't warn about redundant $ for a $ b{c=d} 2.1.3, released 2018-04-18 Improve the performance of the camelCase hint Don't suggest camelCase for record fields
README.md view
@@ -15,7 +15,7 @@ * The presence of `seq` may cause some hints (i.e. eta-reduction) to change the semantics of a program. * Some transformed programs may require additional type signatures, particularly if the transformations trigger the monomorphism restriction or involve rank-2 types. * The `RebindableSyntax` extension can cause HLint to suggest incorrect changes.-* HLint turns on many language extensions so it can parse more documents, occasionally some break otherwise legal syntax - e.g. `{-#INLINE foo#-}` doesn't work with `MagicHash`. These extensions can be disabled with `-XNoMagicHash`.+* HLint turns on many language extensions so it can parse more documents, occasionally some break otherwise legal syntax - e.g. `{-#INLINE foo#-}` doesn't work with `MagicHash`, `foo $bar` means something different with `TemplateHaskell`. These extensions can be disabled with `-XNoMagicHash` or `-XNoTemplateHaskell` etc. ## Installing and running HLint
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.18 build-type: Simple name: hlint-version: 2.1.3+version: 2.1.4 license: BSD3 license-file: LICENSE category: Development
src/HSE/Util.hs view
@@ -121,6 +121,8 @@ isLCase LCase{} = True; isLCase _ = False isTupleSection TupleSection{} = True; isTupleSection _ = False isString String{} = True; isString _ = False+isRecUpdate RecUpdate{} = True; isRecUpdate _ = False+isRecConstr RecConstr{} = True; isRecConstr _ = False isSection LeftSection{} = True isSection RightSection{} = True
src/Hint/Bracket.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-} {- Raise an error if you are bracketing an atom, or are enclosed be a list bracket @@ -42,7 +42,7 @@ yes = white $ keysymbol -- white keysymbol yes = operator foo $ operator -- operator foo operator no = operator foo $ operator bar-yes = return $ Record{a=b} -- return Record{a=b}+yes = return $ Record{a=b} -- $/bracket rotation tests yes = (b $ c d) ++ e -- b (c d) ++ e@@ -66,6 +66,10 @@ main = operate <$> (select $ from $ \user -> return $ user ^. UserEmail) -- unknown fixity, see #426 bad x = x . (x +? x . x)+-- special case people don't like to warn on+special = foo $ f{x=1}+special = foo $ Rec{x=1}+special = foo (f{x=1}) </TEST> -} @@ -79,9 +83,9 @@ bracketHint :: DeclHint bracketHint _ _ x =- concatMap (\x -> bracket True x ++ dollar x) (childrenBi (descendBi annotations x) :: [Exp_]) ++- concatMap (bracket False) (childrenBi x :: [Type_]) ++- concatMap (bracket False) (childrenBi x :: [Pat_]) +++ concatMap (\x -> bracket isPartialAtom True x ++ dollar x) (childrenBi (descendBi annotations x) :: [Exp_]) +++ concatMap (bracket (const False) False) (childrenBi x :: [Type_]) +++ concatMap (bracket (const False) False) (childrenBi x :: [Pat_]) ++ concatMap fieldDecl (childrenBi x) where -- Brackets at the roots of annotations are fine, so we strip them@@ -90,6 +94,9 @@ Paren _ x -> x x -> x +isPartialAtom :: Exp_ -> Bool+isPartialAtom x = isRecConstr x || isRecUpdate x+ -- Dirty, should add to Brackets type class I think tyConToRtype :: String -> RType tyConToRtype "Exp" = Expr@@ -107,16 +114,16 @@ where go e = maybe e go (remParen e) -bracket :: (Data (a S), ExactP a, Pretty (a S), Brackets (a S)) => Bool -> a S -> [Idea]-bracket bad = f Nothing+bracket :: forall a . (Data (a S), ExactP a, Pretty (a S), Brackets (a S)) => (a S -> Bool) -> Bool -> a S -> [Idea]+bracket isPartialAtom root = f Nothing where msg = "Redundant bracket" -- f (Maybe (index, parent, gen)) child f :: (Data (a S), ExactP a, Pretty (a S), Brackets (a S)) => Maybe (Int,a S,a S -> a S) -> a S -> [Idea]- f Just{} o@(remParens -> Just x) | isAtom x = bracketError msg o x : g x- f Nothing o@(remParens -> Just x) | bad || isAtom x = (if isAtom x then bracketError else bracketWarning) msg o x : g x- f (Just (i,o,gen)) v@(remParens -> Just x) | not $ needBracket i o x =+ f Just{} o@(remParens -> Just x) | isAtom x, not $ isPartialAtom x = bracketError msg o x : g x+ f Nothing o@(remParens -> Just x) | root || isAtom x = (if isAtom x then bracketError else bracketWarning) msg o x : g x+ f (Just (i,o,gen)) v@(remParens -> Just x) | not $ needBracket i o x, not $ isPartialAtom x = suggest msg o (gen x) [r] : g x where typ = findType v@@ -142,7 +149,7 @@ dollar = concatMap f . universe where f x = [suggest "Redundant $" x y [r] | InfixApp _ a d b <- [x], opExp d ~= "$"- ,let y = App an a b, not $ needBracket 0 y a, not $ needBracket 1 y b+ ,let y = App an a b, not $ needBracket 0 y a, not $ needBracket 1 y b, not $ isPartialAtom b ,let r = Replace Expr (toSS x) [("a", toSS a), ("b", toSS b)] "a b"] ++ [suggest "Move brackets to avoid $" x (t y) [r] |(t, e@(Paren _ (InfixApp _ a1 op1 a2))) <- splitInfix x
src/Hint/Match.hs view
@@ -65,7 +65,7 @@ readRule :: HintRule -> [HintRule]-readRule (m@HintRule{hintRuleLHS=(fmapAn -> hintRuleLHS), hintRuleRHS=(fmapAn -> hintRuleRHS), hintRuleSide=(fmap fmapAn -> hintRuleSide)}) =+readRule m@HintRule{hintRuleLHS=(fmapAn -> hintRuleLHS), hintRuleRHS=(fmapAn -> hintRuleRHS), hintRuleSide=(fmap fmapAn -> hintRuleSide)} = (:) m{hintRuleLHS=hintRuleLHS,hintRuleSide=hintRuleSide,hintRuleRHS=hintRuleRHS} $ do (l,v1) <- dotVersion hintRuleLHS (r,v2) <- dotVersion hintRuleRHS