hlint 1.6.20 → 1.6.21
raw patch · 13 files changed
+89/−13 lines, 13 filesdep ~haskell-src-extsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: haskell-src-exts
API changes (from Hackage documentation)
Files
- data/Default.hs +10/−0
- data/hs-lint.el +1/−1
- hlint.cabal +2/−2
- src/FindHints.hs +2/−2
- src/HSE/All.hs +16/−2
- src/HSE/Bracket.hs +1/−0
- src/HSE/Util.hs +17/−0
- src/Hint/Bracket.hs +3/−0
- src/Hint/Extensions.hs +4/−2
- src/Hint/Import.hs +24/−2
- src/Hint/Match.hs +1/−1
- src/Hint/Monad.hs +7/−0
- src/Parallel.hs +1/−1
data/Default.hs view
@@ -39,6 +39,11 @@ -- LIST error = concat (map f x) ==> concatMap f x+warn = concat [a,b] ==> a ++ b+-- these hints pick up way too much+--warn = a++b++c++d++e++f++g ==> concat [a, b, c, d, e, f, g]+--warn = a++b++c++d++e++f ==> concat [a, b, c, d, e, f]+--warn = a++b++c++d++e ==> concat [a, b, c, d, e] error "Use map once" = map f (map g x) ==> map (f . g) x warn = x !! 0 ==> head x error = take n (repeat x) ==> replicate n x@@ -161,6 +166,7 @@ error = catMaybes (map f x) ==> mapMaybe f x error = concatMap (maybeToList . f) ==> Data.Maybe.mapMaybe f error = concatMap maybeToList ==> catMaybes+error = maybe n Just x ==> Control.Monad.mplus x n warn = (case x of Nothing -> y; Just a -> a) ==> fromMaybe y x warn = (case x of Just a -> a; Nothing -> y) ==> fromMaybe y x @@ -224,6 +230,8 @@ error "Evaluate" = x * 1 ==> x error "Evaluate" = x / 1 ==> x error "Evaluate" = id x ==> x+error "Evaluate" = concat [a] ==> a+error "Evaluate" = concat [] ==> [] -- COMPLEX @@ -293,6 +301,8 @@ yes x = case x of {False -> a ; _ -> b} -- if x then b else a no = const . ok . toResponse $ "saved" yes = case x z of Nothing -> y z; Just pattern -> pattern -- fromMaybe (y z) (x z)+yes = if p then s else return () -- Control.Monad.when p $ s+error = a $$$$ b $$$$ c ==> a . b $$$$$ c import Prelude \
data/hs-lint.el view
@@ -119,7 +119,7 @@ "Run HLint for current buffer with haskell source" (interactive) (save-some-buffers hs-lint-save-files)- (compilation-start (concat hs-lint-command " " buffer-file-name)+ (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"") 'hs-lint-mode)) (provide 'hs-lint)
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.6 build-type: Simple name: hlint-version: 1.6.20+version: 1.6.21 -- license is GPL v2 only license: GPL license-file: LICENSE@@ -37,7 +37,7 @@ base == 4.*, process, filepath, directory, mtl, containers, hscolour == 1.16.*, cpphs == 1.11.*,- haskell-src-exts == 1.8.* && >= 1.8.1,+ haskell-src-exts == 1.8.* && >= 1.8.2, uniplate == 1.5.* ghc-options: -fno-warn-overlapping-patterns
src/FindHints.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE PatternGuards, ViewPatterns #-}+{-# LANGUAGE PatternGuards #-} module FindHints(findHints) where @@ -38,7 +38,7 @@ rhs = apps $ Var an name : map snd rep rep = zip vs $ map (toNamed . return) ['a'..]- f (view -> Var_ x) | Just y <- lookup x rep = y+ f xx | Var_ x <- view xx, Just y <- lookup x rep = y f (InfixApp _ x dol y) | isDol dol = App an x (paren y) f x = x
src/HSE/All.hs view
@@ -10,6 +10,7 @@ import Util import Data.List+import Data.Maybe import HSE.Util import HSE.Evaluate import HSE.Type@@ -17,6 +18,7 @@ import HSE.Match import HSE.NameMatch import Language.Preprocessor.Cpphs+import Language.Haskell.Exts.Annotated.Simplify(sOp, sAssoc) data ParseFlags = ParseFlags@@ -37,14 +39,26 @@ parseString :: ParseFlags -> FilePath -> String -> IO (String, ParseResult Module_) parseString flags file str = do ppstr <- maybe return (`runCpphs` file) (cpphs flags) str- return (ppstr, parseFileContentsWithMode mode ppstr)+ return (ppstr, fmap (applyFixity fixity) $ parseFileContentsWithMode mode ppstr) where+ fixity = concat [infix_ (-1) ["==>"] | implies flags] ++ baseFixities mode = defaultParseMode {parseFilename = file ,extensions = extension- ,fixities = concat [infix_ (-1) ["==>"] | implies flags] ++ baseFixities+ ,fixities = [] ,ignoreLinePragmas = False }+++-- resolve fixities later, so we don't ever get uncatchable ambiguity errors+-- if there are fixity errors, just ignore them+applyFixity :: [Fixity] -> Module_ -> Module_+applyFixity fixity modu = descendBi f modu+ where+ f x = fromMaybe x $ applyFixities (fixity ++ extra) x :: Decl_++ -- taken from HSE, Fixity.hs+ extra = [Fixity (sAssoc a) p (sOp op) | InfixDecl _ a mp ops <- moduleDecls modu, let p = maybe 9 id mp, op <- ops] parseFile :: ParseFlags -> FilePath -> IO (String, ParseResult Module_)
src/HSE/Bracket.hs view
@@ -57,6 +57,7 @@ | isDotApp parent, isDotApp child, i == 1 = False | RecConstr{} <- parent = False | RecUpdate{} <- parent, i /= 0 = False+ | Lambda{} <- parent, i == length (universeBi parent :: [Pat_]) - 1 = False -- watch out for PViewPat | otherwise = True
src/HSE/Util.hs view
@@ -68,7 +68,9 @@ isPBangPat PBangPat{} = True; isPBangPat _ = False isPExplTypeArg PExplTypeArg{} = True; isPExplTypeArg _ = False isPFieldPun PFieldPun{} = True; isPFieldPun _ = False+isFieldPun FieldPun{} = True; isFieldPun _ = False isPFieldWildcard PFieldWildcard{} = True; isPFieldWildcard _ = False+isFieldWildcard FieldWildcard{} = True; isFieldWildcard _ = False isPViewPat PViewPat{} = True; isPViewPat _ = False isParComp ParComp{} = True; isParComp _ = False isPatTypeSig PatTypeSig{} = True; isPatTypeSig _ = False@@ -119,6 +121,21 @@ getEquations (FunBind s xs) = map (FunBind s . (:[])) xs getEquations (PatBind s (PVar _ name) _ bod bind) = [FunBind s [Match s name [] bod bind]] getEquations x = [x]+++-- case and if both have branches, nothing else does+replaceBranches :: Exp s -> ([Exp s], [Exp s] -> Exp s)+replaceBranches (If s a b c) = ([b,c], \[b,c] -> If s a b c)+replaceBranches (Case s a bs) = (concatMap f bs, \bs2 -> Case s a (g bs bs2))+ where+ f (Alt _ _ (UnGuardedAlt _ x) _) = [x]+ f (Alt _ _ (GuardedAlts _ xs) _) = [x | GuardedAlt _ _ x <- xs]+ g (Alt s1 a (UnGuardedAlt s2 _) b:rest) (x:xs) = Alt s1 a (UnGuardedAlt s2 x) b : g rest xs+ g (Alt s1 a (GuardedAlts s2 ns) b:rest) xs =+ Alt s1 a (GuardedAlts s2 [GuardedAlt a b x | (GuardedAlt a b _,x) <- zip ns as]) b : g rest bs+ where (as,bs) = splitAt (length ns) xs+ g [] [] = []+replaceBranches x = ([], \[] -> x) ---------------------------------------------------------------------
src/Hint/Bracket.hs view
@@ -17,6 +17,8 @@ yes = [(foo bar)] -- @Warning [foo bar] yes = foo ((x y), z) -- @Warning (x y, z) yes = C { f = (e h) } -- @Warning C {f = e h}+yes = \ x -> (x && x) -- @Warning \x -> x && x+no = \(x -> y) -> z -- type bracket reduction foo :: (Int -> Int) -> Int@@ -34,6 +36,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} -- $/bracket rotation tests yes = (b $ c d) ++ e -- b (c d) ++ e
src/Hint/Extensions.hs view
@@ -23,6 +23,8 @@ sort !f = undefined {-# LANGUAGE KindSignatures #-} \ data Set (cxt :: * -> *) a = Set [a]+{-# LANGUAGE RecordWildCards #-} \+record field = Record{..} </TEST> -} @@ -69,8 +71,8 @@ g _ = True used StandaloneDeriving = hasS isDerivDecl used PatternSignatures = hasS isPatTypeSig-used RecordWildCards = hasS isPFieldWildcard-used RecordPuns = hasS isPFieldPun+used RecordWildCards = hasS isPFieldWildcard & hasS isFieldWildcard+used RecordPuns = hasS isPFieldPun & hasS isFieldPun used UnboxedTuples = has isBoxed used PackageImports = hasS (isJust . importPkg) used QuasiQuotes = hasS isQuasiQuote
src/Hint/Import.hs view
@@ -25,6 +25,8 @@ import qualified A; import A import B; import A; import A -- import A import A hiding(Foo); import A hiding(Bar)+import List -- import Data.List+import Locale(foo) -- import System.Locale(foo) </TEST> -} @@ -39,8 +41,9 @@ importHint :: ModuHint-importHint _ x = concatMap (wrap . snd) $ groupSortFst- [((fromNamed $ importModule i,importPkg i),i) | i <- universeBi x, not $ importSrc i]+importHint _ x = concatMap (wrap . snd) (groupSortFst+ [((fromNamed $ importModule i,importPkg i),i) | i <- universeBi x, not $ importSrc i]) +++ concatMap hierarchy (universeBi x) wrap :: [ImportDecl S] -> [Idea]@@ -84,3 +87,22 @@ specs = importSpecs x `eqMaybe` importSpecs y reduce _ _ = Nothing++++newNames = let (*) = flip (,) in+ ["Control" * "Monad"+ ,"Data" * "Char"+ ,"Data" * "List"+ ,"Data" * "Maybe"+ ,"Data" * "Ratio"+ ,"System" * "Directory"+ ,"System" * "IO"+ ,"System" * "Locale"+ ,"System" * "Time"+ ]++hierarchy :: ImportDecl S -> [Idea]+hierarchy i@ImportDecl{importModule=ModuleName _ x} | Just y <- lookup x newNames+ = [warn "Use hierarchical imports" i i{importModule=ModuleName an $ y ++ "." ++ x}]+hierarchy _ = []
src/Hint/Match.hs view
@@ -151,7 +151,7 @@ f (Var _ (fromNamed -> x)) | isUnifyVar x = lookup x bind f _ = Nothing - g (App _ np (Paren _ x)) | np ~= "_noParen_" = x+ g (App _ np x) | np ~= "_noParen_" = fromParen x g x = x
src/Hint/Monad.hs view
@@ -24,6 +24,9 @@ yes = do x <- return $ y + z; foo x -- do let x = y + z; foo x no = do x <- return x; foo x no = do x <- return y; x <- return y; foo x+yes = do forM files $ \x -> return (); return () -- forM_ files $ \x -> return ()+yes = do if a then forM x y else sequence z q; return () -- if a then forM_ x y else sequence_ z q+yes = do case a of {_ -> forM x y; x:xs -> forM x xs}; return () -- case a of _ -> forM_ x y ; x:xs -> forM_ x xs </TEST> -} @@ -58,9 +61,13 @@ -- see through Paren and down if/case etc+-- return the name to use in the hint, and the revised expression monadCall :: Exp_ -> Maybe (String,Exp_) monadCall (Paren _ x) = fmap (second $ Paren an) $ monadCall x monadCall (App _ x y) = fmap (second $ \x -> App an x y) $ monadCall x+monadCall (InfixApp _ x dol y) | isDol dol = fmap (second $ \x -> InfixApp an x dol y) $ monadCall x+monadCall (replaceBranches -> (bs@(_:_), gen)) | all isJust res = Just (fst $ fromJust $ head res, gen $ map (snd . fromJust) res)+ where res = map monadCall bs monadCall x | x:_ <- filter (x ~=) badFuncs = let x2 = x ++ "_" in Just (x2, toNamed x2) monadCall _ = Nothing
src/Parallel.hs view
@@ -23,7 +23,7 @@ parallelN xs = do ms <- mapM (const newEmptyMVar) xs chan <- newChan- mapM (writeChan chan . Just) $ zip ms xs+ mapM_ (writeChan chan . Just) $ zip ms xs replicateM_ numCapabilities (writeChan chan Nothing >> forkIO (f chan)) parallel1 $ map takeMVar ms where