Using HLint API!.
This commit is contained in:
parent
6e6e1c9ad7
commit
740ab2a054
@ -31,16 +31,12 @@ usage = "ghc-mod version 0.4.1\n"
|
|||||||
defaultOptions :: Options
|
defaultOptions :: Options
|
||||||
defaultOptions = Options {
|
defaultOptions = Options {
|
||||||
convert = toPlain
|
convert = toPlain
|
||||||
, hlint = "hlint"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
argspec :: [OptDescr (Options -> Options)]
|
argspec :: [OptDescr (Options -> Options)]
|
||||||
argspec = [ Option "l" ["tolisp"]
|
argspec = [ Option "l" ["tolisp"]
|
||||||
(NoArg (\opts -> opts { convert = toLisp }))
|
(NoArg (\opts -> opts { convert = toLisp }))
|
||||||
"print as a list of Lisp"
|
"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])
|
parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String])
|
||||||
|
16
Lint.hs
16
Lint.hs
@ -2,19 +2,17 @@ module Lint where
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.List
|
import Data.List
|
||||||
import System.IO
|
import Language.Haskell.HLint
|
||||||
import System.Process
|
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
lintSyntax :: Options -> String -> IO String
|
lintSyntax :: Options -> String -> IO String
|
||||||
lintSyntax cmd file = pretty <$> lint cmd file
|
lintSyntax _ file = pretty <$> lint file
|
||||||
where
|
where
|
||||||
pretty = unlines . map (concat . intersperse "\0")
|
pretty = unlines . map (concat . intersperse "\0")
|
||||||
. filter (\x -> length x > 1)
|
. filter (\x -> length x > 1)
|
||||||
. groupBy (\a b -> a /= "" && b /= "")
|
. groupBy (\a b -> a /= "" && b /= "") . lines
|
||||||
. lines
|
|
||||||
|
|
||||||
lint :: Options -> String -> IO String
|
lint :: String -> IO String
|
||||||
lint cmd file = do
|
lint file = toString <$> hlint [file, "--quiet", "--ignore=Use camelCase"]
|
||||||
(_,hout,_,_) <- runInteractiveProcess (hlint cmd) ["-i","Use camelCase",file] Nothing Nothing
|
where
|
||||||
hGetContents hout
|
toString = concat . map show
|
||||||
|
1
Types.hs
1
Types.hs
@ -6,7 +6,6 @@ import GHC.Paths (libdir)
|
|||||||
|
|
||||||
data Options = Options {
|
data Options = Options {
|
||||||
convert :: [String] -> String
|
convert :: [String] -> String
|
||||||
, hlint :: String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
withGHC :: Ghc [String] -> IO [String]
|
withGHC :: Ghc [String] -> IO [String]
|
||||||
|
@ -29,7 +29,7 @@ Executable ghc-mod
|
|||||||
else
|
else
|
||||||
GHC-Options: -Wall
|
GHC-Options: -Wall
|
||||||
Build-Depends: base >= 4.0 && < 5, ghc, ghc-paths,
|
Build-Depends: base >= 4.0 && < 5, ghc, ghc-paths,
|
||||||
process, directory, filepath
|
process, directory, filepath, hlint
|
||||||
Source-Repository head
|
Source-Repository head
|
||||||
Type: git
|
Type: git
|
||||||
Location: git://github.com/kazu-yamamoto/ghc-mod.git
|
Location: git://github.com/kazu-yamamoto/ghc-mod.git
|
||||||
|
Loading…
Reference in New Issue
Block a user