hlint 3.2.6 → 3.2.7
raw patch · 10 files changed
+29/−10 lines, 10 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.txt +4/−0
- LICENSE +1/−1
- README.md +1/−1
- data/hlint.yaml +4/−0
- hlint.cabal +2/−2
- src/CmdLine.hs +1/−1
- src/GHC/Util/HsExpr.hs +3/−2
- src/GHC/Util/Unify.hs +10/−1
- src/GHC/Util/View.hs +2/−2
- src/Hint/Lambda.hs +1/−0
CHANGES.txt view
@@ -1,5 +1,9 @@ Changelog for HLint (* = breaking change) +3.2.7, released 2021-01-16+ #1202, add missing parentheses for Avoid Lambda+ #1201, allow matching through the & operator (similar to $)+ #1196, fix removed parens with operator sections in some cases 3.2.6, released 2020-12-30 Fixes to the release generation script 3.2.5, released 2020-12-30
LICENSE view
@@ -1,4 +1,4 @@-Copyright Neil Mitchell 2006-2020.+Copyright Neil Mitchell 2006-2021. All rights reserved. Redistribution and use in source and binary forms, with or without
README.md view
@@ -397,7 +397,7 @@ Getting started on problems in HLint often means wanting to inspect a GHC parse tree to get a sense of what it looks like (to see how to match on it for example). Given a source program `Foo.hs` (say), you can get GHC to print a textual representation of `Foo`'s AST via the `-ddump-parsed-ast` flag e.g. `ghc -fforce-recomp -ddump-parsed-ast -c Foo.hs`. -When you have an [`HsSyn`](https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hs-syn-type) term in your program, it's quite common to want to print it (e.g. via `Debug.Trace.trace`). Types in `HsSyn` aren't in [`Show`](https://hoogle.haskell.org/?hoogle=Show). Not all types in `HsSyn` are [`Outputable`](https://hoogle.haskell.org/?hoogle=Outputable) but when they are you can call `ppr` to get `SDoc`s. This idiom is common enough that there exists [`unsafePrettyPrint`](https://hackage.haskell.org/package/ghc-lib-parser-ex-8.10.0.16/docs/Language-Haskell-GhclibParserEx-GHC-Utils-Outputable.html#v:unsafePrettyPrint). The function [`showAstData`](https://hoogle.haskell.org/?hoogle=showAstData) can be called on any `HsSyn` term to get output like with the `dump-parsed-ast` flag. The `showAstData` approach is preferable to `ppr` when both choices exist in that two ASTs that differ only in fixity arrangments will render differently with the former.+When you have an [`HsSyn`](https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hs-syn-type) term in your program, it's quite common to want to print it (e.g. via `Debug.Trace.trace`). Types in `HsSyn` aren't in [`Show`](https://hoogle.haskell.org/?hoogle=Show). Not all types in `HsSyn` are [`Outputable`](https://hoogle.haskell.org/?hoogle=Outputable) but when they are you can call `ppr` to get `SDoc`s. This idiom is common enough that there exists [`unsafePrettyPrint`](https://hackage.haskell.org/package/ghc-lib-parser-ex-8.10.0.16/docs/Language-Haskell-GhclibParserEx-GHC-Utils-Outputable.html#v:unsafePrettyPrint). The function [`showAstData`](https://hoogle.haskell.org/?hoogle=showAstData) can be called on any `HsSyn` term to get output like with the `dump-parsed-ast` flag. The `showAstData` approach is preferable to `ppr` when both choices exist in that two ASTs that differ only in fixity arrangements will render differently with the former. ### Acknowledgements
data/hlint.yaml view
@@ -1047,6 +1047,7 @@ # yes = f x where f x = concat . map head -- concatMap head # yes = concat . map f . g -- concatMap f . g # yes = concat $ map f x -- concatMap f x+# yes = map f x & concat -- concatMap f x # yes = "test" ++ concatMap (' ':) ["of","this"] -- unwords ("test":["of","this"]) # yes = if f a then True else b -- f a || b # yes = not (a == b) -- a /= b@@ -1201,6 +1202,7 @@ # no = foo $ (,) x $ do {this is a test; and another test} # no = sequence (return x) # no = sequenceA (pure a)+# yes = zipWith func xs ys & sequenceA -- Control.Monad.zipWithM func xs ys # {-# LANGUAGE QuasiQuotes #-}; no = f (\url -> [hamlet|foo @{url}|]) # yes = f ((,) x) -- (x,) # yes = f ((,) (2 + 3)) -- (2 + 3,)@@ -1257,7 +1259,9 @@ # fromList [] -- Data.Map.Strict.empty # test953 = for [] $ \n -> bar n >>= \case {Just n -> pure (); Nothing -> baz n} # f = map (flip (,) "a") "123" -- (,"a")+# test1196 = map (flip (,) (+ 1)) "123" -- (,(+ 1)) # f = map ((,) "a") "123" -- ("a",)+# test1196 = map ((,) (+ 1)) "123" -- ((+ 1),) # test979 = flip Map.traverseWithKey blocks \k v -> lots_of_code_goes_here # infixl 4 <*! \ # test993 = f =<< g <$> x <*! y
hlint.cabal view
@@ -1,13 +1,13 @@ cabal-version: >= 1.18 build-type: Simple name: hlint-version: 3.2.6+version: 3.2.7 license: BSD3 license-file: LICENSE category: Development author: Neil Mitchell <ndmitchell@gmail.com> maintainer: Neil Mitchell <ndmitchell@gmail.com>-copyright: Neil Mitchell 2006-2020+copyright: Neil Mitchell 2006-2021 synopsis: Source code suggestions description: HLint gives suggestions on how to improve your source code.
src/CmdLine.hs view
@@ -172,7 +172,7 @@ ,"To check all Haskell files in 'src' and generate a report type:" ," hlint src --report"] ] &= program "hlint" &= verbosity- &= summary ("HLint v" ++ showVersion version ++ ", (C) Neil Mitchell 2006-2020")+ &= summary ("HLint v" ++ showVersion version ++ ", (C) Neil Mitchell 2006-2021") where nam xs = nam_ xs &= name [head xs] nam_ xs = def &= explicit &= name xs
src/GHC/Util/HsExpr.hs view
@@ -33,6 +33,7 @@ import Data.Generics.Uniplate.DataOnly import Data.List.Extra import Data.Tuple.Extra+import Data.Maybe import Refact (substVars, toSS) import Refact.Types hiding (SrcSpan, Match)@@ -227,6 +228,7 @@ ) where gen = noLoc . HsApp noExtField (strToVar "flip")+ . if isAtom op then id else addParen -- We're done factoring, but have no variables left, so we shouldn't make a lambda. -- @\ -> e@ ==> @e@@@ -306,5 +308,4 @@ _ -> False fromParen1 :: LHsExpr GhcPs -> LHsExpr GhcPs-fromParen1 (L _ (HsPar _ x)) = x-fromParen1 x = x+fromParen1 x = fromMaybe x $ remParen x
src/GHC/Util/Unify.hs view
@@ -26,6 +26,7 @@ import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader import GHC.Util.HsExpr import GHC.Util.View+import Data.Maybe import FastString isUnifyVar :: String -> Bool@@ -171,6 +172,7 @@ | (L _ (OpApp _ lhs1 op1@(L _ (HsVar _ op1')) rhs1)) <- x = guard (nm op1' op2') >> (, Nothing) <$> liftA2 (<>) (unifyExp' nm False lhs1 lhs2) (unifyExp' nm False rhs1 rhs2) | isDol op2 = unifyExp nm root x $ noLoc (HsApp noExtField lhs2 rhs2)+ | isAmp op2 = unifyExp nm root x $ noLoc (HsApp noExtField rhs2 lhs2) | otherwise = unifyExp nm root x $ noLoc (HsApp noExtField (noLoc (HsApp noExtField op2 (addPar lhs2))) (addPar rhs2)) where -- add parens around when desugaring the expression, if necessary@@ -179,6 +181,9 @@ unifyExp nm root x y = (, Nothing) <$> unifyExp' nm root x y +isAmp :: LHsExpr GhcPs -> Bool+isAmp (L _ (HsVar _ x)) = rdrNameStr x == "&"+ -- | If we "throw away" the extra than we have no where to put it, and the substitution is wrong noExtra :: Maybe (Subst (LHsExpr GhcPs), Maybe (LHsExpr GhcPs)) -> Maybe (Subst (LHsExpr GhcPs)) noExtra (Just (x, Nothing)) = Just x@@ -197,7 +202,11 @@ -- Brackets are not added when expanding '$' in user code, so tolerate -- them in the match even if they aren't in the user code. -- Also, allow the user to put in more brackets than they strictly need (e.g. with infix).-unifyExp' nm root x y | not root, isPar x || isPar y = unifyExp' nm root (fromParen x) (fromParen y)+unifyExp' nm root x y | not root, isJust x2 || isJust y2 = unifyExp' nm root (fromMaybe x x2) (fromMaybe y y2)+ where+ -- Make sure we deal with the weird brackets that can't be removed around sections+ x2 = remParen x+ y2 = remParen y unifyExp' nm root x@(L _ (OpApp _ lhs1 (L _ (HsVar _ (rdrNameStr -> v))) rhs1)) y@(L _ (OpApp _ lhs2 (L _ (HsVar _ op2)) rhs2)) =
src/GHC/Util/View.hs view
@@ -12,10 +12,10 @@ import SrcLoc import BasicTypes import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader+import GHC.Util.Brackets fromParen :: LHsExpr GhcPs -> LHsExpr GhcPs-fromParen (L _ (HsPar _ x)) = fromParen x-fromParen x = x+fromParen x = maybe x fromParen $ remParen x fromPParen :: LPat GhcPs -> LPat GhcPs fromPParen (L _ (ParPat _ x)) = fromPParen x
src/Hint/Lambda.hs view
@@ -63,6 +63,7 @@ f = a b (\x -> c x d) -- (`c` d) yes = \x -> a x where -- a yes = \x y -> op y x where -- flip op+yes = \x y -> op z y x where -- flip (op z) f = \y -> nub $ reverse y where -- nub . reverse f = \z -> foo $ bar $ baz z where -- foo . bar . baz f = \z -> foo $ bar x $ baz z where -- foo . bar x . baz