Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore suppressed issues in sarif reports #1110

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
}
}

@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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SImplify with getOrDefault("suppressed", "false")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! updated to match

}

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,26 @@ void handleBrokenPathsInFileURIschemeFormat(final String fileName) {
}
}

@Test
void shouldIgnoreSuppressedIssues() {
var report = parse("suppressed-sarif.json");
try (var softly = new SoftAssertions()) {
softly.assertThat(report).hasSize(2);
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");
softly.assertThat(report.get(1))
.hasFileName("/whatever/path.c")
.hasLineStart(123)
.hasType("abcdef")
.hasSeverity(Severity.WARNING_LOW);
softly.assertThat(report.get(1).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,173 @@
{
"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": "abcdef",
"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": "rejected",
"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": []
}
Loading