From 740ab2a054e06676ad1da27f290418abefac9446 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 8 Jun 2010 11:12:59 +0900 Subject: [PATCH] Using HLint API!. --- GHCMod.hs | 4 ---- Lint.hs | 16 +++++++--------- Types.hs | 1 - ghc-mod.cabal | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/GHCMod.hs b/GHCMod.hs index 1b190b3..d0e9867 100644 --- a/GHCMod.hs +++ b/GHCMod.hs @@ -31,16 +31,12 @@ usage = "ghc-mod version 0.4.1\n" defaultOptions :: Options defaultOptions = Options { convert = toPlain - , hlint = "hlint" } argspec :: [OptDescr (Options -> Options)] argspec = [ Option "l" ["tolisp"] (NoArg (\opts -> opts { convert = toLisp })) "print as a list of Lisp" - , Option "f" ["hlint"] - (ReqArg (\str opts -> opts { hlint = str }) "hlint") - "path to hlint" ] parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String]) diff --git a/Lint.hs b/Lint.hs index b6bea3e..5c8322b 100644 --- a/Lint.hs +++ b/Lint.hs @@ -2,19 +2,17 @@ module Lint where import Control.Applicative import Data.List -import System.IO -import System.Process +import Language.Haskell.HLint import Types lintSyntax :: Options -> String -> IO String -lintSyntax cmd file = pretty <$> lint cmd file +lintSyntax _ file = pretty <$> lint file where pretty = unlines . map (concat . intersperse "\0") . filter (\x -> length x > 1) - . groupBy (\a b -> a /= "" && b /= "") - . lines + . groupBy (\a b -> a /= "" && b /= "") . lines -lint :: Options -> String -> IO String -lint cmd file = do - (_,hout,_,_) <- runInteractiveProcess (hlint cmd) ["-i","Use camelCase",file] Nothing Nothing - hGetContents hout +lint :: String -> IO String +lint file = toString <$> hlint [file, "--quiet", "--ignore=Use camelCase"] + where + toString = concat . map show diff --git a/Types.hs b/Types.hs index 18a332e..b84d631 100644 --- a/Types.hs +++ b/Types.hs @@ -6,7 +6,6 @@ import GHC.Paths (libdir) data Options = Options { convert :: [String] -> String - , hlint :: String } withGHC :: Ghc [String] -> IO [String] diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 6621a62..ed1f053 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -29,7 +29,7 @@ Executable ghc-mod else GHC-Options: -Wall Build-Depends: base >= 4.0 && < 5, ghc, ghc-paths, - process, directory, filepath + process, directory, filepath, hlint Source-Repository head Type: git Location: git://github.com/kazu-yamamoto/ghc-mod.git