From f30eb343b0547f372ff977c1a54716e4ef0c0fc6 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Mon, 14 Jun 2010 11:56:35 +0900 Subject: [PATCH] hlint options can be specified from ghc-hlint-options. --- GHCMod.hs | 6 +++++- Lint.hs | 6 +++--- Types.hs | 3 ++- elisp/ghc-flymake.el | 13 ++++++++++--- elisp/ghc-func.el | 5 +++++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/GHCMod.hs b/GHCMod.hs index 98f7d80..9bc4a78 100644 --- a/GHCMod.hs +++ b/GHCMod.hs @@ -22,7 +22,7 @@ usage = "ghc-mod version 0.4.2\n" ++ "\t ghc-mod lang\n" ++ "\t ghc-mod browse [ ...]\n" ++ "\t ghc-mod check \n" - ++ "\t ghc-mod lint \n" + ++ "\t ghc-mod [-h opt] lint \n" ++ "\t ghc-mod boot\n" ++ "\t ghc-mod help\n" @@ -31,12 +31,16 @@ usage = "ghc-mod version 0.4.2\n" defaultOptions :: Options defaultOptions = Options { convert = toPlain + , hlintOpts = [] } argspec :: [OptDescr (Options -> Options)] argspec = [ Option "l" ["tolisp"] (NoArg (\opts -> opts { convert = toLisp })) "print as a list of Lisp" + , Option "h" ["hlintOpt"] + (ReqArg (\h opts -> opts { hlintOpts = h : hlintOpts opts }) "hlintOpt") + "hint to be ignored" ] parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String]) diff --git a/Lint.hs b/Lint.hs index 014fd01..91a51d0 100644 --- a/Lint.hs +++ b/Lint.hs @@ -6,9 +6,9 @@ import Language.Haskell.HLint import Types lintSyntax :: Options -> String -> IO String -lintSyntax _ file = pretty <$> lint file +lintSyntax opt file = pretty <$> lint opt file where pretty = unlines . map (concat . intersperse "\0" . lines) -lint :: String -> IO [String] -lint file = map show <$> hlint [file, "--quiet", "--ignore=Use camelCase"] +lint :: Options -> String -> IO [String] +lint opt file = map show <$> hlint ([file, "--quiet"] ++ hlintOpts opt) diff --git a/Types.hs b/Types.hs index b84d631..50d2b59 100644 --- a/Types.hs +++ b/Types.hs @@ -5,7 +5,8 @@ import GHC import GHC.Paths (libdir) data Options = Options { - convert :: [String] -> String + convert :: [String] -> String + , hlintOpts :: [String] } withGHC :: Ghc [String] -> IO [String] diff --git a/elisp/ghc-flymake.el b/elisp/ghc-flymake.el index 574550f..96840f1 100644 --- a/elisp/ghc-flymake.el +++ b/elisp/ghc-flymake.el @@ -10,6 +10,12 @@ (require 'flymake) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defvar ghc-hlint-options nil "*Hlint options") + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defvar ghc-error-buffer-name "*GHC Errors*") (defvar ghc-flymake-allowed-file-name-masks @@ -30,13 +36,14 @@ (let ((after-save-hook nil)) (save-buffer)) (let ((file (file-name-nondirectory (buffer-file-name)))) - (list ghc-module-command (ghc-flymake-command file)))) + (list ghc-module-command (ghc-flymake-command file ghc-hlint-options)))) (defvar ghc-flymake-command nil) ;; nil: check, t: lint -(defun ghc-flymake-command (file) +(defun ghc-flymake-command (file opts) (if ghc-flymake-command - (list "lint" file) + (let ((hopts (ghc-mapconcat (lambda (x) (list "-h" x)) opts))) + `(,@hopts "lint" ,file)) (list "check" file))) (defun ghc-flymake-toggle-command () diff --git a/elisp/ghc-func.el b/elisp/ghc-func.el index 493c0e2..09c58b9 100644 --- a/elisp/ghc-func.el +++ b/elisp/ghc-func.el @@ -81,6 +81,11 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun ghc-mapconcat (func list) + (apply 'append (mapcar func list))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defconst ghc-null 0) (defconst ghc-newline 10)