Added gcc compatible output for editor integrations
This commit is contained in:
parent
2e13cedc4b
commit
376d407ea1
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
GHCFLAGS=-O9
|
GHCFLAGS=-O9
|
||||||
|
|
||||||
all: shellcheck jsoncheck .tests
|
all: shellcheck .tests
|
||||||
: Done
|
: Done
|
||||||
|
|
||||||
shellcheck: regardless
|
shellcheck: regardless
|
||||||
|
|
|
@ -52,21 +52,19 @@ parseArguments argv =
|
||||||
(opts, files, []) ->
|
(opts, files, []) ->
|
||||||
if not $ null files
|
if not $ null files
|
||||||
then
|
then
|
||||||
return $ Just (opts, map specials files)
|
return $ Just (opts, files)
|
||||||
else do
|
else do
|
||||||
printErr "No files specified.\n"
|
printErr "No files specified.\n"
|
||||||
printErr $ usageInfo header options
|
printErr $ usageInfo header options
|
||||||
return $ Nothing
|
return $ Nothing
|
||||||
|
|
||||||
(_, _, errors) -> do
|
(_, _, errors) -> do
|
||||||
printErr $ (unlines errors) ++ "\n" ++ usageInfo header options
|
printErr $ (concat errors) ++ "\n" ++ usageInfo header options
|
||||||
return Nothing
|
return Nothing
|
||||||
where
|
|
||||||
specials "-" = "/dev/stdin"
|
|
||||||
specials x = x
|
|
||||||
|
|
||||||
formats = Map.fromList [
|
formats = Map.fromList [
|
||||||
("json", forJson),
|
("json", forJson),
|
||||||
|
("gcc", forGcc),
|
||||||
("tty", forTty)
|
("tty", forTty)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -88,15 +86,8 @@ forTty options files = do
|
||||||
colorComment level comment = (ansi $ colorForLevel level) ++ comment ++ clear
|
colorComment level comment = (ansi $ colorForLevel level) ++ comment ++ clear
|
||||||
|
|
||||||
doFile path = do
|
doFile path = do
|
||||||
let actualPath = if path == "-" then "/dev/stdin" else path
|
contents <- readContents path
|
||||||
exists <- doesFileExist actualPath
|
doInput path contents
|
||||||
if exists then do
|
|
||||||
contents <- readFile actualPath
|
|
||||||
doInput path contents
|
|
||||||
else do
|
|
||||||
colorFunc <- getColorFunc
|
|
||||||
printErr (colorFunc "error" $ "No such file: " ++ actualPath)
|
|
||||||
return False
|
|
||||||
|
|
||||||
doInput filename contents = do
|
doInput filename contents = do
|
||||||
let fileLines = lines contents
|
let fileLines = lines contents
|
||||||
|
@ -128,13 +119,35 @@ forTty options files = do
|
||||||
|
|
||||||
-- This totally ignores the filenames. Fixme?
|
-- This totally ignores the filenames. Fixme?
|
||||||
forJson options files = do
|
forJson options files = do
|
||||||
comments <- liftM concat $ mapM process files
|
comments <- liftM concat $ mapM commentsFor files
|
||||||
putStrLn $ encodeStrict $ comments
|
putStrLn $ encodeStrict $ comments
|
||||||
return . null $ comments
|
return . null $ comments
|
||||||
|
|
||||||
|
--- Mimic GCC "file:line:col: (error|warning|note): message" format
|
||||||
|
forGcc options files = do
|
||||||
|
files <- mapM process files
|
||||||
|
return $ and files
|
||||||
where
|
where
|
||||||
process file = do
|
process file = do
|
||||||
script <- readFile file
|
comments <- commentsFor file
|
||||||
return $ shellCheck script
|
mapM_ (putStrLn . format file) comments
|
||||||
|
return $ null comments
|
||||||
|
|
||||||
|
format filename c = concat [
|
||||||
|
filename, ":",
|
||||||
|
show $ scLine c, ":",
|
||||||
|
show $ scColumn c, ": ",
|
||||||
|
case scSeverity c of
|
||||||
|
"error" -> "error"
|
||||||
|
"warning" -> "warning"
|
||||||
|
_ -> "note",
|
||||||
|
": ",
|
||||||
|
concat . lines $ scMessage c,
|
||||||
|
" [SC", show $ scCode c, "]"
|
||||||
|
]
|
||||||
|
|
||||||
|
commentsFor file = liftM shellCheck $ readContents file
|
||||||
|
readContents file = if file == "-" then getContents else readFile file
|
||||||
|
|
||||||
getOption [] _ def = def
|
getOption [] _ def = def
|
||||||
getOption ((Flag var val):_) name _ | name == var = val
|
getOption ((Flag var val):_) name _ | name == var = val
|
||||||
|
|
Loading…
Reference in New Issue