mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-09 08:21:39 +08:00
Add json1 format that ignores tabs
The new json1 format works just like json except that it treats tabs as single characters instead of 8-character tabstops. The main use case is to allow editors to pass -fjson1 so that they can consume the json output in a character-oriented way without breaking backwards compatibility. Also addresses #1048.
This commit is contained in:
@@ -30,11 +30,12 @@ import GHC.Exts
|
||||
import System.IO
|
||||
import qualified Data.ByteString.Lazy.Char8 as BL
|
||||
|
||||
format = do
|
||||
format :: Bool -> IO Formatter
|
||||
format removeTabs = do
|
||||
ref <- newIORef []
|
||||
return Formatter {
|
||||
header = return (),
|
||||
onResult = collectResult ref,
|
||||
onResult = collectResult removeTabs ref,
|
||||
onFailure = outputError,
|
||||
footer = finish ref
|
||||
}
|
||||
@@ -96,8 +97,20 @@ instance ToJSON Fix where
|
||||
]
|
||||
|
||||
outputError file msg = hPutStrLn stderr $ file ++ ": " ++ msg
|
||||
collectResult ref result _ =
|
||||
modifyIORef ref (\x -> crComments result ++ x)
|
||||
|
||||
collectResult removeTabs 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)
|
||||
|
||||
finish ref = do
|
||||
list <- readIORef ref
|
||||
|
Reference in New Issue
Block a user