2013-05-17 01:00:01 +00:00
|
|
|
module Language.Haskell.GhcMod.Lint where
|
2010-05-06 06:29:55 +00:00
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
import Exception (ghandle)
|
|
|
|
import Control.Exception (SomeException(..))
|
2014-07-11 02:12:05 +00:00
|
|
|
import CoreMonad (liftIO)
|
2014-04-28 12:47:08 +00:00
|
|
|
import Language.Haskell.GhcMod.Logger (checkErrorPrefix)
|
2014-05-11 22:40:00 +00:00
|
|
|
import Language.Haskell.GhcMod.Convert
|
2014-07-11 01:10:37 +00:00
|
|
|
import Language.Haskell.GhcMod.Monad
|
2014-03-27 06:56:14 +00:00
|
|
|
import Language.Haskell.HLint (hlint)
|
2010-05-06 06:29:55 +00:00
|
|
|
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | Checking syntax of a target file using hlint.
|
|
|
|
-- Warnings and errors are returned.
|
2014-07-12 09:16:16 +00:00
|
|
|
lint :: IOish m
|
|
|
|
=> FilePath -- ^ A target file.
|
|
|
|
-> GhcModT m String
|
2014-07-11 01:10:37 +00:00
|
|
|
lint file = do
|
|
|
|
opt <- options
|
|
|
|
ghandle handler . pack =<< (liftIO $ hlint $ file : "--quiet" : hlintOpts opt)
|
|
|
|
where
|
|
|
|
pack = convert' . map (init . show) -- init drops the last \n.
|
2014-04-25 02:08:29 +00:00
|
|
|
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
|