Skip to content

Commit

Permalink
enhance(errors): set dynamic ruleId based on ErrorKind
Browse files Browse the repository at this point in the history
Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
  • Loading branch information
royalpinto007 authored and thewilsonator committed Nov 1, 2024
1 parent a2194b0 commit 2b89c29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion compiler/src/dmd/sarif.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,27 @@ void generateSarifReport(const ref SourceLoc loc, const(char)* format, va_list a

// Map ErrorKind to SARIF levels
const(char)* level;
string ruleId;
final switch (kind) {
case ErrorKind.error:
level = "error";
ruleId = "DMD-ERROR";
break;
case ErrorKind.warning:
level = "warning";
ruleId = "DMD-WARNING";
break;
case ErrorKind.deprecation:
level = "deprecation";
ruleId = "DMD-DEPRECATION";
break;
case ErrorKind.tip:
level = "note";
ruleId = "DMD-NOTE";
break;
case ErrorKind.message:
level = "none";
ruleId = "DMD-MESSAGE";
break;
}

Expand Down Expand Up @@ -258,7 +264,11 @@ void generateSarifReport(const ref SourceLoc loc, const(char)* format, va_list a
// Results Array
ob.writestringln(`"results": [{`);
ob.level += 1;
ob.writestringln(`"ruleId": "DMD",`);

// Rule ID
ob.writestring(`"ruleId": "`);
ob.writestring(ruleId);
ob.writestringln(`",`);

// Message Information
ob.writestringln(`"message": {`);
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/sarif_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TEST_OUTPUT:
"executionSuccessful": false
}],
"results": [{
"ruleId": "DMD",
"ruleId": "DMD-ERROR",
"message": {
"text": "undefined identifier `x`"
},
Expand Down

0 comments on commit 2b89c29

Please sign in to comment.