Use HLint3.hlint in Lint

Related: #826
This commit is contained in:
Nikolay Yakimov 2016-08-27 19:33:26 +03:00
parent 90bcf63d6c
commit 57a31c348d

View File

@ -9,8 +9,7 @@ import Language.Haskell.GhcMod.Monad
import Language.Haskell.HLint3 import Language.Haskell.HLint3
import Language.Haskell.GhcMod.Utils (withMappedFile) import Language.Haskell.GhcMod.Utils (withMappedFile)
import Language.Haskell.Exts.SrcLoc (SrcLoc(..)) import Language.Haskell.Exts.SrcLoc (SrcSpan(..))
import System.IO
-- | Checking syntax of a target file using hlint. -- | Checking syntax of a target file using hlint.
-- Warnings and errors are returned. -- Warnings and errors are returned.
@ -20,15 +19,12 @@ lint :: IOish m
-> GhcModT m String -> GhcModT m String
lint opt file = ghandle handler $ lint opt file = ghandle handler $
withMappedFile file $ \tempfile -> do withMappedFile file $ \tempfile -> do
(flags, classify, hint) <- liftIO $ argsSettings $ optLintHlintOpts opt res <- liftIO $ hlint $ "--quiet" : tempfile : optLintHlintOpts opt
hSrc <- liftIO $ openFile tempfile ReadMode pack . map (show . substFile file tempfile) $ res
liftIO $ hSetEncoding hSrc (encoding flags)
res <- liftIO $ parseModuleEx flags file =<< Just `fmap` hGetContents hSrc
case res of
Right m -> pack . map show $ filter ((/=Ignore) . ideaSeverity) $ applyHints classify hint [m]
Left ParseError{parseErrorLocation=loc, parseErrorMessage=err} ->
return $ showSrcLoc loc ++ ":Error:" ++ err ++ "\n"
where where
pack = convert' . map init -- init drops the last \n. pack = convert' . map init -- init drops the last \n.
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n" handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
showSrcLoc (SrcLoc f l c) = concat [f, ":", show l, ":", show c] substFile orig temp idea
| srcSpanFilename (ideaSpan idea) == temp
= idea{ideaSpan=(ideaSpan idea){srcSpanFilename = orig}}
substFile _ _ idea = idea