diff --git a/ShellCheck.cabal b/ShellCheck.cabal index 099052e..d54f0b8 100644 --- a/ShellCheck.cabal +++ b/ShellCheck.cabal @@ -80,6 +80,7 @@ library ShellCheck.Formatter.CheckStyle ShellCheck.Formatter.GCC ShellCheck.Formatter.JSON + ShellCheck.Formatter.JSON1 ShellCheck.Formatter.TTY ShellCheck.Formatter.Quiet ShellCheck.Interface diff --git a/shellcheck.hs b/shellcheck.hs index 02ed88a..351e1c2 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -27,6 +27,7 @@ import qualified ShellCheck.Formatter.CheckStyle import ShellCheck.Formatter.Format import qualified ShellCheck.Formatter.GCC import qualified ShellCheck.Formatter.JSON +import qualified ShellCheck.Formatter.JSON1 import qualified ShellCheck.Formatter.TTY import qualified ShellCheck.Formatter.Quiet @@ -141,8 +142,8 @@ formats :: FormatterOptions -> Map.Map String (IO Formatter) formats options = Map.fromList [ ("checkstyle", ShellCheck.Formatter.CheckStyle.format), ("gcc", ShellCheck.Formatter.GCC.format), - ("json", ShellCheck.Formatter.JSON.format False), -- JSON with 8-char tabs - ("json1", ShellCheck.Formatter.JSON.format True), -- JSON with 1-char tabs + ("json", ShellCheck.Formatter.JSON.format), + ("json1", ShellCheck.Formatter.JSON1.format), ("tty", ShellCheck.Formatter.TTY.format options), ("quiet", ShellCheck.Formatter.Quiet.format options) ] diff --git a/src/ShellCheck/Formatter/JSON.hs b/src/ShellCheck/Formatter/JSON.hs index c3f3219..7c26421 100644 --- a/src/ShellCheck/Formatter/JSON.hs +++ b/src/ShellCheck/Formatter/JSON.hs @@ -30,12 +30,12 @@ import GHC.Exts import System.IO import qualified Data.ByteString.Lazy.Char8 as BL -format :: Bool -> IO Formatter -format removeTabs = do +format :: IO Formatter +format = do ref <- newIORef [] return Formatter { header = return (), - onResult = collectResult removeTabs ref, + onResult = collectResult ref, onFailure = outputError, footer = finish ref } @@ -98,19 +98,12 @@ instance ToJSON Fix where outputError file msg = hPutStrLn stderr $ file ++ ": " ++ msg -collectResult removeTabs ref cr sys = mapM_ f groups +collectResult ref cr sys = mapM_ f groups where comments = crComments cr groups = groupWith sourceFile comments f :: [PositionedComment] -> IO () - f group = do - let filename = sourceFile (head group) - result <- siReadFile sys filename - let contents = either (const "") id result - let comments' = if removeTabs - then makeNonVirtual comments contents - else comments - modifyIORef ref (\x -> comments' ++ x) + f group = modifyIORef ref (\x -> comments ++ x) finish ref = do list <- readIORef ref