Skip to content

Commit

Permalink
Only a text property of a message affects a baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
avafanasiev committed Jul 15, 2024
1 parent 505d3e5 commit ea5f1fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public boolean equals(Object o) {
ResultKey key = (ResultKey) o;
Result oResult = key.result;

if (!Objects.equals(result.getMessage(), oResult.getMessage()) ||
if (!equalsMessage(result.getMessage(), oResult.getMessage()) ||
!Objects.equals(result.getRuleId(), oResult.getRuleId()) ||
!Objects.equals(result.getLevel(), oResult.getLevel())
) {
Expand All @@ -49,6 +49,11 @@ public boolean equals(Object o) {
return true;
}

private boolean equalsMessage(Message message, Message oMessage) {
if (message == null || oMessage== null) return message == oMessage;
return message.getText().equals(oMessage.getText());
}

private boolean equalsLocation(Location location, Location oLocation) {
if (location == null || oLocation == null) return location == oLocation;

Expand Down Expand Up @@ -100,7 +105,7 @@ private boolean equalsArtifactLocation(ArtifactLocation artifactLocation, Artifa
public int hashCode() {
int hash = 1;
hash = ((hash * 31) + ((result.getRuleId() == null) ? 0 : result.getRuleId().hashCode()));
hash = ((hash * 31) + ((result.getMessage() == null) ? 0 : result.getMessage().hashCode()));
hash = ((hash * 31) + ((result.getMessage() == null) ? 0 : hashMessage(result.getMessage())));
hash = ((hash * 31) + ((result.getLevel() == null) ? 0 : result.getLevel().hashCode()));

if (result.getLocations() == null) return hash;
Expand All @@ -120,6 +125,11 @@ public int hashCode() {
return hash;
}

private int hashMessage(Message message) {
if (message == null) return 0;
return message.getText().hashCode();
}


public int hashPhysicalLocation(PhysicalLocation location) {
if (location == null) return 0;
Expand Down
10 changes: 10 additions & 0 deletions sarif/src/test/java/com/jetbrains/qodana/sarif/BaselineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ public void testDoUseLogicalLocationsIfProblemHasNotPhysical() {
doTest(report, baseline, 0, 1, 1, INCLUDE_ABSENT);
}

@Test
public void testMarkdownInMessageDoNotAffectBaseline() {
SarifReport report = newReport();
SarifReport baseline = newReport();
report.getRuns().get(0).getResults().get(0).getMessage().withMarkdown("1");
baseline.getRuns().get(0).getResults().get(0).getMessage().withMarkdown("2");

doTest(report, baseline, 1, 0, 0, INCLUDE_ABSENT);
}

private SarifReport newReport() {
return new SarifReport()
.withRuns(
Expand Down

0 comments on commit ea5f1fa

Please sign in to comment.