2017-05-28 02:22:56 +00:00
|
|
|
module GhcMod.Exe.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(..))
|
2017-05-28 02:22:56 +00:00
|
|
|
import GhcMod.Logger (checkErrorPrefix)
|
|
|
|
import GhcMod.Convert
|
|
|
|
import GhcMod.Types
|
|
|
|
import GhcMod.Monad
|
2016-01-05 07:14:07 +00:00
|
|
|
import Language.Haskell.HLint3
|
2010-05-06 06:29:55 +00:00
|
|
|
|
2017-05-28 02:22:56 +00:00
|
|
|
import GhcMod.Utils (withMappedFile)
|
2016-08-27 16:33:26 +00:00
|
|
|
import Language.Haskell.Exts.SrcLoc (SrcSpan(..))
|
2015-07-02 18:45:07 +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
|
2015-12-07 16:57:33 +00:00
|
|
|
=> LintOpts -- ^ Configuration parameters
|
2015-12-05 20:55:12 +00:00
|
|
|
-> FilePath -- ^ A target file.
|
2014-07-12 09:16:16 +00:00
|
|
|
-> GhcModT m String
|
2016-01-05 07:14:07 +00:00
|
|
|
lint opt file = ghandle handler $
|
|
|
|
withMappedFile file $ \tempfile -> do
|
2016-08-27 16:33:26 +00:00
|
|
|
res <- liftIO $ hlint $ "--quiet" : tempfile : optLintHlintOpts opt
|
|
|
|
pack . map (show . substFile file tempfile) $ res
|
2016-01-05 07:14:07 +00:00
|
|
|
where
|
2015-07-02 18:45:07 +00:00
|
|
|
pack = convert' . map init -- init drops the last \n.
|
2014-04-25 02:08:29 +00:00
|
|
|
handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n"
|
2016-08-27 16:33:26 +00:00
|
|
|
substFile orig temp idea
|
|
|
|
| srcSpanFilename (ideaSpan idea) == temp
|
|
|
|
= idea{ideaSpan=(ideaSpan idea){srcSpanFilename = orig}}
|
|
|
|
substFile _ _ idea = idea
|