implementing suppressStdout/err.

This commit is contained in:
Kazu Yamamoto
2014-04-18 15:41:32 +09:00
parent 5006d836e1
commit aecb9bc1e4
4 changed files with 46 additions and 18 deletions

View File

@@ -1,13 +1,10 @@
module Language.Haskell.GhcMod.Lint where
import Control.Applicative ((<$>))
import Control.Exception (finally)
import Data.List (intercalate)
import GHC.IO.Handle (hDuplicate, hDuplicateTo)
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Utils
import Language.Haskell.HLint (hlint)
import System.Directory (getTemporaryDirectory, removeFile)
import System.IO (hClose, openTempFile, stdout)
-- | Checking syntax of a target file using hlint.
-- Warnings and errors are returned.
@@ -26,14 +23,3 @@ lint :: [String]
-> FilePath -- ^ A target file.
-> IO [String]
lint hopts file = map show <$> suppressStdout (hlint (file : hopts))
suppressStdout :: IO a -> IO a
suppressStdout f = do
tmpdir <- getTemporaryDirectory
(path, handle) <- openTempFile tmpdir "ghc-mod-hlint"
dup <- hDuplicate stdout
hDuplicateTo handle stdout
hClose handle
f `finally` do
hDuplicateTo dup stdout
removeFile path