2013-05-17 10:00:01 +09:00
|
|
|
module Language.Haskell.GhcMod.Lint where
|
2010-05-06 15:29:55 +09:00
|
|
|
|
2014-07-11 03:10:37 +02:00
|
|
|
import Exception (ghandle)
|
|
|
|
|
import Control.Exception (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
|
2014-07-11 03:10:37 +02:00
|
|
|
import Language.Haskell.GhcMod.Monad
|
2014-07-17 14:30:42 +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
|
|
|
|
2015-07-03 06:43:32 +03:00
|
|
|
import Language.Haskell.GhcMod.Utils (withMappedFile)
|
2015-07-02 21:45:07 +03:00
|
|
|
|
|
|
|
|
import Data.List (stripPrefix)
|
|
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Checking syntax of a target file using hlint.
|
|
|
|
|
-- Warnings and errors are returned.
|
2014-07-12 11:16:16 +02:00
|
|
|
lint :: IOish m
|
|
|
|
|
=> FilePath -- ^ A target file.
|
|
|
|
|
-> GhcModT m String
|
2014-07-11 03:10:37 +02:00
|
|
|
lint file = do
|
|
|
|
|
opt <- options
|
2015-07-02 21:45:07 +03:00
|
|
|
withMappedFile file $ \tempfile ->
|
2015-09-01 10:27:12 +02:00
|
|
|
liftIO (hlint $ tempfile : "--quiet" : optHlintOpts opt)
|
2015-07-02 21:45:07 +03:00
|
|
|
>>= mapM (replaceFileName tempfile)
|
|
|
|
|
>>= ghandle handler . pack
|
2014-07-11 03:10:37 +02:00
|
|
|
where
|
2015-07-02 21:45:07 +03:00
|
|
|
pack = convert' . map init -- init drops the last \n.
|
2014-04-25 11:08:29 +09:00
|
|
|
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
|
2015-07-02 21:45:07 +03:00
|
|
|
replaceFileName fp s = return $ maybe (show s) (file++) $ stripPrefix fp (show s)
|