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