Skip to content

Commit 53994e8

Browse files
committed
json-writer: print level key in SARIF output
... so that users can easily filter results according to their severity. Fixes: #80
1 parent d9ede63 commit 53994e8

9 files changed

+12475
-0
lines changed

src/json-writer.cc

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <queue>
2828

29+
#include <boost/algorithm/string/predicate.hpp>
2930
#include <boost/iostreams/filtering_stream.hpp>
3031
#include <boost/iostreams/filter/regex.hpp>
3132
#include <boost/nowide/utf/convert.hpp>
@@ -214,6 +215,19 @@ static void sarifEncodeMsg(PTree *pDst, const std::string& text)
214215
pDst->put_child("message", msg);
215216
}
216217

218+
static void sarifEncodeLevel(PTree *result, const std::string &event) {
219+
std::string level = "warning";
220+
221+
if (boost::starts_with(event, "error"))
222+
level = "error";
223+
else if (boost::starts_with(event, "warning"))
224+
level = "warning";
225+
else if (boost::starts_with(event, "note"))
226+
level = "note";
227+
228+
result->put<std::string>("level", level);
229+
}
230+
217231
static void sarifEncodeLoc(PTree *pLoc, const Defect &def, unsigned idx)
218232
{
219233
// location ID within the result
@@ -291,6 +305,9 @@ void SarifTreeEncoder::appendDef(const Defect &def)
291305
// update CWE map
292306
cweMap_[ruleId] = def.cwe;
293307

308+
// key event severity level
309+
sarifEncodeLevel(&result, keyEvt.event);
310+
294311
// key event location
295312
PTree loc;
296313
sarifEncodeLoc(&loc, def, def.keyEventIdx);

0 commit comments

Comments
 (0)