From b15a00458aead818e7e3a8f12c76cd7417de4fe0 Mon Sep 17 00:00:00 2001 From: Etan Reisner Date: Sun, 26 Apr 2015 19:23:47 -0400 Subject: [PATCH] Add a JUnit output format style. This code is almost entirely based on the checkstyle format code. --- shellcheck.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/shellcheck.hs b/shellcheck.hs index 7111c83..e9505e4 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -89,6 +89,7 @@ formats = Map.fromList [ ("json", forJson), ("gcc", forGcc), ("checkstyle", forCheckstyle), + ("junit", forJunit), ("tty", forTty) ] @@ -228,6 +229,47 @@ forCheckstyle options files = do "/>\n" ] +-- JUnit compatible output. A bit of a hack to avoid XML dependencies +forJunit :: AnalysisOptions -> [FilePath] -> IO Status +forJunit options files = do + putStrLn "" + putStrLn "" + statuses <- mapM process files + putStrLn "" + return $ mconcat statuses + where + process file = catchExceptions $ do + comments <- commentsFor options file + putStrLn (formatFile file comments) + return $ checkComments comments + + severity "error" = "error" + severity "warning" = "warning" + severity _ = "info" + attr s v = concat [ s, "='", escape v, "' " ] + escape = concatMap escape' + escape' c = if isOk c then [c] else "&#" ++ show (ord c) ++ ";" + isOk x = any ($x) [isAsciiUpper, isAsciiLower, isDigit, (`elem` " ./")] + + formatFile name comments = concat [ + "\n\n", + "\n\n", + concatMap format comments, + "" + ] + + format c = concat [ + "\n", + "\n\n" + ] + + commentsFor options file = liftM (getComments options) $ readContents file getComments = shellCheck