diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.java index 45e46f5e7..95cc0d6d3 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.java @@ -40,6 +40,12 @@ void extractAdditionalProperties(final IssueBuilder builder, final Violation vio } } + @Override + boolean isValid(final Violation violation) { + return !(violation.getSpecifics().containsKey("suppressed") + && violation.getSpecifics().get("suppressed").equals("true")); + } + private String removePrefix(final String fileName) { if (WINDOWS_PATH_ON_UNIX.matcher(fileName).matches()) { return fileName.substring(1); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/violations/SarifAdapterTest.java b/src/test/java/edu/hm/hafner/analysis/parser/violations/SarifAdapterTest.java index 24fe7447a..34dd227ae 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/violations/SarifAdapterTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/violations/SarifAdapterTest.java @@ -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(); diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/violations/suppressed-sarif.json b/src/test/resources/edu/hm/hafner/analysis/parser/violations/suppressed-sarif.json new file mode 100644 index 000000000..6e3c3d86a --- /dev/null +++ b/src/test/resources/edu/hm/hafner/analysis/parser/violations/suppressed-sarif.json @@ -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": [] +}