hlint 1.8.17 → 1.8.18
raw patch · 7 files changed
+59/−19 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- data/Default.hs +2/−2
- data/Test.hs +4/−0
- hlint.cabal +1/−1
- src/CmdLine.hs +40/−12
- src/Hint/Import.hs +10/−2
- src/Hint/Match.hs +1/−1
- src/Hint/Structure.hs +1/−1
data/Default.hs view
@@ -167,7 +167,7 @@ error "Monad law, left identity" = return a >>= f ==> f a error "Monad law, right identity" = m >>= return ==> m-warn = m >>= return . f ==> fmap f m+warn = m >>= return . f ==> Control.Monad.liftM f m -- cannot be fmap, because is in Functor not Monad error = (if x then y else return ()) ==> Control.Monad.when x $ _noParen_ y where _ = not (isAtom y) error = (if x then y else return ()) ==> Control.Monad.when x y where _ = isAtom y error = (if x then return () else y) ==> Control.Monad.unless x $ _noParen_ y where _ = not (isAtom y)@@ -336,7 +336,7 @@ yes = not (a /= b) -- a == b yes = if a then 1 else if b then 1 else 2 -- if a || b then 1 else 2 no = if a then 1 else if b then 3 else 2-yes = a >>= return . id -- fmap id a+yes = a >>= return . id -- Control.Monad.liftM id a yes = (x !! 0) + (x !! 2) -- head x yes = if b < 42 then [a] else [] -- [a | b < 42] yes = take 5 (foo xs) == "hello" -- "hello" `Data.List.isPrefixOf` foo xs
data/Test.hs view
@@ -39,7 +39,9 @@ error = Array.head ==> head error = tail ==> Array.tail +error = zip [1..length x] x ==> zipFrom 1 x + {- <TEST> main = readFile "foo" >>= putStr \@@ -84,5 +86,7 @@ import Array as A; test = A.head -- head test = tail -- Array.tail import qualified Array as B; test = tail -- B.tail+zip [1..length x]+zip [1..length x] x -- zipFrom 1 x </TEST> -}
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.6 build-type: Simple name: hlint-version: 1.8.17+version: 1.8.18 -- license is GPL v2 only license: GPL license-file: LICENSE
src/CmdLine.hs view
@@ -3,6 +3,7 @@ module CmdLine(Cmd(..), CppFlags(..), getCmd, exitWithHelp) where import Control.Monad+import Data.Char import Data.List import Data.Maybe import System.Console.GetOpt@@ -39,7 +40,7 @@ ,cmdFindHints :: [FilePath] -- ^ source files to look for hints in ,cmdLanguage :: [Extension] -- ^ the extensions (may be prefixed by "No") ,cmdQuiet :: Bool -- ^ supress all console output- ,cmdCross :: Bool -- ^ work between source files+ ,cmdCross :: Bool -- ^ work between source files, applies to hints such as duplicate code between modules } @@ -47,6 +48,7 @@ | Ver | Test | Hints FilePath+ | Path FilePath | Report FilePath | Skip String | ShowAll@@ -80,6 +82,7 @@ ,Option "f" ["find"] (ReqArg FindHints "file") "Find hints in a Haskell file" ,Option "t" ["test"] (NoArg Test) "Run in test mode" ,Option "d" ["datadir"] (ReqArg DataDir "dir") "Override the data directory"+ ,Option "p" ["path"] (ReqArg Path "dir") "Directory in which to search for files" ,Option "q" ["quiet"] (NoArg Quiet) "Supress most console output" ,Option "" ["cpp-define"] (ReqArg Define "name[=value]") "CPP #define" ,Option "" ["cpp-include"] (ReqArg Include "dir") "CPP include path"@@ -107,8 +110,9 @@ let exts = [x | Ext x <- opt] exts2 = if null exts then ["hs","lhs"] else exts- files <- if null files then return Nothing else fmap Just $ concatMapM (getFile exts2) files- findHints <- concatMapM (getFile exts2) [x | FindHints x <- opt]+ let path = [x | Path x <- opt] ++ ["."]+ files <- if null files then return Nothing else fmap Just $ concatMapM (getFile path exts2) files+ findHints <- concatMapM (getFile path exts2) [x | FindHints x <- opt] let hintFiles = [x | Hints x <- opt] hints <- mapM (getHintFile dataDir) $ hintFiles ++ ["HLint" | null hintFiles]@@ -167,18 +171,42 @@ ," hlint src --report" ] +"." <\> x = x+x <\> y = x </> y -getFile :: [String] -> FilePath -> IO [FilePath]-getFile _ "-" = return ["-"]-getFile exts file = do- b <- doesDirectoryExist file- if b then do- xs <- getDirectoryContentsRecursive file++getFile :: [FilePath] -> [String] -> FilePath -> IO [FilePath]+getFile path _ "-" = return ["-"]+getFile [] exts file = error $ "Couldn't find file: " ++ file+getFile (p:ath) exts file = do+ isDir <- doesDirectoryExist $ p <\> file+ if isDir then do+ xs <- getDirectoryContentsRecursive $ p <\> file return [x | x <- xs, drop 1 (takeExtension x) `elem` exts] else do- b <- doesFileExist file- unless b $ error $ "Couldn't find file: " ++ file- return [file]+ isFil <- doesFileExist $ p <\> file+ if isFil then return [p <\> file]+ else do+ res <- getModule p exts file+ case res of+ Just x -> return [x]+ Nothing -> getFile ath exts file+++getModule :: FilePath -> [String] -> FilePath -> IO (Maybe FilePath)+getModule path exts x | not (any isSpace x) && all isMod xs = f exts+ where+ xs = words $ map (\x -> if x == '.' then ' ' else x) x+ isMod (x:xs) = isUpper x && all (\x -> isAlphaNum x || x == '_') xs+ isMod _ = False+ pre = path <\> joinPath xs++ f [] = return Nothing+ f (x:xs) = do+ let s = pre <.> x+ b <- doesFileExist s+ if b then return $ Just s else f xs+getModule _ _ _ = return Nothing getHintFile :: FilePath -> FilePath -> IO FilePath
src/Hint/Import.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}+{-# LANGUAGE PatternGuards, ScopedTypeVariables, RecordWildCards #-} {- Reduce the number of import declarations. Two import declarations can be combined if:@@ -21,6 +21,8 @@ import A; import A as Y -- import A as Y import A; import qualified A as Y import A as B; import A as C+import A as A -- import A+import qualified A as A -- import qualified A import A; import B; import A -- import A import qualified A; import A import B; import A; import A -- import A@@ -49,7 +51,7 @@ importHint :: ModuHint importHint _ x = concatMap (wrap . snd) (groupSortFst [((fromNamed $ importModule i,importPkg i),i) | i <- universeBi x, not $ importSrc i]) ++- concatMap hierarchy (universeBi x) +++ concatMap (\x -> hierarchy x ++ reduce1 x) (universeBi x) ++ multiExport x @@ -87,6 +89,12 @@ reduce _ _ = Nothing ++reduce1 :: ImportDecl S -> [Idea]+reduce1 i@ImportDecl{..}+ | Just (dropAnn importModule) == fmap dropAnn importAs+ = [warn "Redundant as" i i{importAs=Nothing}]+reduce1 _ = [] newNames = let (*) = flip (,) in
src/Hint/Match.hs view
@@ -59,7 +59,7 @@ (:) m{lhs=lhs,side=side,rhs=rhs} $ fromMaybe [] $ do (l,v1) <- dotVersion lhs (r,v2) <- dotVersion rhs- guard $ v1 == v2 && l /= [] && r /= [] && v1 `notElem` vars side+ guard $ v1 == v2 && l /= [] && r /= [] && v1 `notElem` (vars side ++ vars l ++ vars r) return [m{lhs=dotApps l, rhs=dotApps r, side=side} ,m{lhs=dotApps (l++[toNamed v1]), rhs=dotApps (r++[toNamed v1]), side=side}] readRule _ = []
src/Hint/Structure.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE ViewPatterns, PatternGuards #-}+{-# LANGUAGE ViewPatterns #-} {- Improve the structure of code