Skip to content

Commit db73cfe

Browse files
authored
Merge pull request github#3378 from github/koesie10/ignore-more-location-indexes
Ignore more location indexes in SARIF comparison
2 parents 3d2d86b + 694bb21 commit db73cfe

File tree

2 files changed

+417
-18
lines changed

2 files changed

+417
-18
lines changed

extensions/ql-vscode/src/compare/sarif-diff.ts

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
1-
import type { Result } from "sarif";
1+
import type { Location, Result } from "sarif";
2+
3+
function toCanonicalLocation(location: Location): Location {
4+
if (location.physicalLocation?.artifactLocation?.index !== undefined) {
5+
const canonicalLocation = {
6+
...location,
7+
};
8+
9+
canonicalLocation.physicalLocation = {
10+
...canonicalLocation.physicalLocation,
11+
};
12+
13+
canonicalLocation.physicalLocation.artifactLocation = {
14+
...canonicalLocation.physicalLocation.artifactLocation,
15+
};
16+
17+
// The index is dependent on the result of the SARIF file and usually doesn't really tell
18+
// us anything useful, so we remove it from the comparison.
19+
delete canonicalLocation.physicalLocation.artifactLocation.index;
20+
21+
return canonicalLocation;
22+
}
23+
24+
// Don't create a new object if we don't need to
25+
return location;
26+
}
227

328
function toCanonicalResult(result: Result): Result {
429
const canonicalResult = {
530
...result,
631
};
732

833
if (canonicalResult.locations) {
9-
canonicalResult.locations = canonicalResult.locations.map((location) => {
10-
if (location.physicalLocation?.artifactLocation?.index !== undefined) {
11-
const canonicalLocation = {
12-
...location,
13-
};
34+
canonicalResult.locations =
35+
canonicalResult.locations.map(toCanonicalLocation);
36+
}
1437

15-
canonicalLocation.physicalLocation = {
16-
...canonicalLocation.physicalLocation,
17-
};
38+
if (canonicalResult.relatedLocations) {
39+
canonicalResult.relatedLocations =
40+
canonicalResult.relatedLocations.map(toCanonicalLocation);
41+
}
1842

19-
canonicalLocation.physicalLocation.artifactLocation = {
20-
...canonicalLocation.physicalLocation.artifactLocation,
21-
};
43+
if (canonicalResult.codeFlows) {
44+
canonicalResult.codeFlows = canonicalResult.codeFlows.map((codeFlow) => {
45+
if (codeFlow.threadFlows) {
46+
return {
47+
...codeFlow,
48+
threadFlows: codeFlow.threadFlows.map((threadFlow) => {
49+
if (threadFlow.locations) {
50+
return {
51+
...threadFlow,
52+
locations: threadFlow.locations.map((threadFlowLocation) => {
53+
if (threadFlowLocation.location) {
54+
return {
55+
...threadFlowLocation,
56+
location: toCanonicalLocation(
57+
threadFlowLocation.location,
58+
),
59+
};
60+
}
2261

23-
// The index is dependent on the result of the SARIF file and usually doesn't really tell
24-
// us anything useful, so we remove it from the comparison.
25-
delete canonicalLocation.physicalLocation.artifactLocation.index;
62+
return threadFlowLocation;
63+
}),
64+
};
65+
}
2666

27-
return canonicalLocation;
67+
return threadFlow;
68+
}),
69+
};
2870
}
2971

30-
// Don't create a new object if we don't need to
31-
return location;
72+
return codeFlow;
3273
});
3374
}
3475

0 commit comments

Comments
 (0)