2013-05-17 10:00:01 +09:00
|
|
|
module Language.Haskell.GhcMod.Lint where
|
2010-05-06 15:29:55 +09:00
|
|
|
|
2014-03-27 15:56:14 +09:00
|
|
|
import Control.Applicative ((<$>))
|
2014-04-25 11:08:29 +09:00
|
|
|
import Control.Exception (handle, SomeException(..))
|
2014-04-28 21:47:08 +09:00
|
|
|
import Language.Haskell.GhcMod.Logger (checkErrorPrefix)
|
2014-05-12 00:40:00 +02:00
|
|
|
import Language.Haskell.GhcMod.Convert
|
2013-05-17 10:00:01 +09:00
|
|
|
import Language.Haskell.GhcMod.Types
|
2014-03-27 15:56:14 +09:00
|
|
|
import Language.Haskell.HLint (hlint)
|
2010-05-06 15:29:55 +09:00
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Checking syntax of a target file using hlint.
|
|
|
|
|
-- Warnings and errors are returned.
|
|
|
|
|
lintSyntax :: Options
|
|
|
|
|
-> FilePath -- ^ A target file.
|
|
|
|
|
-> IO String
|
2014-04-25 11:08:29 +09:00
|
|
|
lintSyntax opt file = handle handler $ pack <$> hlint (file : "--quiet" : hopts)
|
2010-05-06 15:29:55 +09:00
|
|
|
where
|
2014-04-21 15:58:36 +09:00
|
|
|
pack = convert opt . map (init . show) -- init drops the last \n.
|
2014-03-27 10:34:30 +09:00
|
|
|
hopts = hlintOpts opt
|
2014-04-25 11:08:29 +09:00
|
|
|
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
|