2013-05-17 01:00:01 +00:00
|
|
|
module Language.Haskell.GhcMod.Lint where
|
2010-05-06 06:29:55 +00:00
|
|
|
|
2014-03-27 06:56:14 +00:00
|
|
|
import Control.Applicative ((<$>))
|
2014-04-25 02:08:29 +00:00
|
|
|
import Control.Exception (handle, SomeException(..))
|
|
|
|
import Language.Haskell.GhcMod.ErrMsg (checkErrorPrefix)
|
2013-05-17 01:00:01 +00:00
|
|
|
import Language.Haskell.GhcMod.Types
|
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.
|
|
|
|
lintSyntax :: Options
|
|
|
|
-> FilePath -- ^ A target file.
|
|
|
|
-> IO String
|
2014-04-25 02:08:29 +00:00
|
|
|
lintSyntax opt file = handle handler $ pack <$> hlint (file : "--quiet" : hopts)
|
2010-05-06 06:29:55 +00:00
|
|
|
where
|
2014-04-21 06:58:36 +00:00
|
|
|
pack = convert opt . map (init . show) -- init drops the last \n.
|
2014-03-27 01:34:30 +00:00
|
|
|
hopts = hlintOpts opt
|
2014-04-25 02:08:29 +00:00
|
|
|
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
|