From 621c9ecfa5313edcb6981aa9be00c85a58b7ab89 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Tue, 14 Nov 2023 21:17:35 +0100 Subject: [PATCH] Translate checkstyle back to plain text. See https://gitlab.com/ci-includes/masslinter/ for an example. --- JUnit2text.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 JUnit2text.md diff --git a/JUnit2text.md b/JUnit2text.md new file mode 100644 index 0000000..7cd4147 --- /dev/null +++ b/JUnit2text.md @@ -0,0 +1,68 @@ +Shellcheck can generate `checkstyle` reports or `tty` outputs, but not both simultaneously. For CI purposes, it might be needed to generate both types however, one for the report, one for the logging output. By using the following xlst, we can translate the checkstyle output to text-based output. + +```xslt + + + + + + + + + + + + + + - + + failure(s) + + + + + + + + + + + + + : + + ( + + ) line + + , column + + - + + + - + + + + +``` + +Since the XSLT cannot show the original line, some sed magic can be used. +```sh +xmlstarlet tr '/tmp/checkstyle2text.xslt' '/path/to/file' | \ +sed 's|"|\\"|g' | \ +sed -n \ + -e "s|^\(.*\) - \([0-9]\+\) failure.*$|echo '========='\n \ + echo 'Found \2 failure(s) in \1'\n \ + echo '---------'|p" \ + -e "s|^\(.*\): \(ShellCheck\.\)\?\(\(..\)[0-9]\{4\}\) (\(.*\)) line \([0-9]\+\), column \([0-9]\+\) - \(.*\)$|echo 'In \1 line \6:'\n \ + sed -n '\6p' \1\n \ + printf \"%\$((\7 - 1\))s^ \"\n \ + printf 'https://www.shellcheck.net/wiki/' \ + echo \"\3 (\5): \8\"\n \ + echo\n|p" | \ +sh | \ +tee -a '/path/to/file.log' +``` + +The generated output is similar to the original `tty` output format. \ No newline at end of file