Skip to content

Commit 6f6901a

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 6f6901a

9 files changed

+12477
-0
lines changed

src/json-writer.cc

+19
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ static void sarifEncodeMsg(PTree *pDst, const std::string& text)
214214
pDst->put_child("message", msg);
215215
}
216216

217+
static void sarifEncodeLevel(PTree *result, const std::string &event) {
218+
const RE error("error(\\[|$)");
219+
const RE warning("warning(\\[|$)");
220+
const RE note("note(\\[|$)");
221+
std::string level = "warning";
222+
223+
if (boost::regex_search(event, error))
224+
level = "error";
225+
else if (boost::regex_search(event, warning))
226+
level = "warning";
227+
else if (boost::regex_search(event, note))
228+
level = "note";
229+
230+
result->put<std::string>("level", level);
231+
}
232+
217233
static void sarifEncodeLoc(PTree *pLoc, const Defect &def, unsigned idx)
218234
{
219235
// location ID within the result
@@ -291,6 +307,9 @@ void SarifTreeEncoder::appendDef(const Defect &def)
291307
// update CWE map
292308
cweMap_[ruleId] = def.cwe;
293309

310+
// key event severity level
311+
sarifEncodeLevel(&result, keyEvt.event);
312+
294313
// key event location
295314
PTree loc;
296315
sarifEncodeLoc(&loc, def, def.keyEventIdx);

0 commit comments

Comments
 (0)