Skip to content

Commit

Permalink
Ignore suppressed issues in sarif reports
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Jonsey committed Nov 26, 2024
1 parent a814e87 commit a203a21
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void extractAdditionalProperties(final IssueBuilder builder, final Violation vio
}
}

@Override
boolean isValid(final Violation violation) {
return !(violation.getSpecifics().containsKey("suppressed")

Check warning on line 45 in src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 45 is only partially covered, one branch is missing
&& violation.getSpecifics().get("suppressed").equals("true"));
}

private String removePrefix(final String fileName) {
if (WINDOWS_PATH_ON_UNIX.matcher(fileName).matches()) {
return fileName.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ void handleBrokenPathsInFileURIschemeFormat(final String fileName) {
}
}

@Test
void shouldIgnoreSuppressedIssues() {
var report = parse("suppressed-sarif.json");
try (var softly = new SoftAssertions()) {
softly.assertThat(report).hasSize(1);
softly.assertThat(report.get(0))
.hasFileName("/whatever/path.c")
.hasLineStart(123)
.hasType("Cyclomatic complexity")
.hasSeverity(Severity.WARNING_HIGH);
softly.assertThat(report.get(0).getMessage()).matches("asdasd");
}
}

@Override
protected SarifAdapter createParser() {
return new SarifAdapter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"runs": [
{
"invocations": [],
"language": "en-US",
"versionControlProvenance": [],
"artifacts": [],
"logicalLocations": [],
"graphs": [],
"results": [
{
"ruleId": "",
"ruleIndex": -1,
"kind": "FAIL",
"level": "note",
"message": {
"text": "asdasd",
"arguments": []
},
"locations": [
{
"id": -1,
"physicalLocation": {
"artifactLocation": {
"uri": "/whatever/path.c",
"index": -1
},
"region": {
"startLine": 123,
"endLine": 123,
"charOffset": -1,
"byteOffset": -1,
"message": {
"text": "asdasd",
"arguments": []
}
}
},
"logicalLocations": [],
"annotations": [],
"relationships": []
}
],
"stacks": [],
"codeFlows": [],
"graphs": [],
"graphTraversals": [],
"relatedLocations": [],
"suppressions": [
{
"state": "accepted",
"justification": "bla"
}
],
"rank": -1.0,
"attachments": [],
"workItemUris": [],
"fixes": [],
"taxa": []
},
{
"ruleId": "Cyclomatic complexity",
"ruleIndex": -1,
"kind": "FAIL",
"level": "error",
"message": {
"text": "asdasd",
"arguments": []
},
"locations": [
{
"id": -1,
"physicalLocation": {
"artifactLocation": {
"uri": "/whatever/path.c",
"index": -1
},
"region": {
"startLine": 123,
"endLine": 123,
"charOffset": -1,
"byteOffset": -1,
"message": {
"text": "asdasd",
"arguments": []
}
}
},
"logicalLocations": [],
"annotations": [],
"relationships": []
}
],
"stacks": [],
"codeFlows": [],
"graphs": [],
"graphTraversals": [],
"relatedLocations": [],
"suppressions": [],
"rank": -1.0,
"attachments": [],
"workItemUris": [],
"fixes": [],
"taxa": []
}
],
"runAggregates": [],
"redactionTokens": [],
"newlineSequences": [
"\r\n",
"\n"
],
"threadFlowLocations": [],
"taxonomies": [],
"addresses": [],
"translations": [],
"policies": [],
"webRequests": [],
"webResponses": []
}
],
"inlineExternalProperties": []
}

0 comments on commit a203a21

Please sign in to comment.