Files
ghc-mod/GhcMod/Lint.hs

31 lines
1.1 KiB
Haskell
Raw Normal View History

module GhcMod.Lint where
2010-05-06 15:29:55 +09: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
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad
2016-01-05 10:14:07 +03:00
import Language.Haskell.HLint3
2010-05-06 15:29:55 +09:00
import Language.Haskell.GhcMod.Utils (withMappedFile)
2016-08-27 19:33:26 +03:00
import Language.Haskell.Exts.SrcLoc (SrcSpan(..))
2015-07-02 21:45:07 +03:00
2013-05-20 14:28:56 +09:00
-- | Checking syntax of a target file using hlint.
-- Warnings and errors are returned.
lint :: IOish m
2015-12-07 19:57:33 +03:00
=> LintOpts -- ^ Configuration parameters
2015-12-05 23:55:12 +03:00
-> FilePath -- ^ A target file.
-> GhcModT m String
2016-01-05 10:14:07 +03:00
lint opt file = ghandle handler $
withMappedFile file $ \tempfile -> do
2016-08-27 19:33:26 +03:00
res <- liftIO $ hlint $ "--quiet" : tempfile : optLintHlintOpts opt
pack . map (show . substFile file tempfile) $ res
2016-01-05 10:14:07 +03: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"
2016-08-27 19:33:26 +03:00
substFile orig temp idea
| srcSpanFilename (ideaSpan idea) == temp
= idea{ideaSpan=(ideaSpan idea){srcSpanFilename = orig}}
substFile _ _ idea = idea