Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
104 changes: 21 additions & 83 deletions extensions/ql-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@
"semver": "^7.7.4",
"source-map": "^0.7.6",
"source-map-support": "^0.5.21",
"stream-json": "^1.9.1",
"stream-json": "^3.5.0",
"styled-components": "^6.5.3",
"tmp": "^0.2.7",
"tmp-promise": "^3.0.2",
Expand Down Expand Up @@ -2141,7 +2141,6 @@
"@types/readable-stream": "^4.0.24",
"@types/sarif": "^2.1.2",
"@types/semver": "^7.7.1",
"@types/stream-json": "^1.7.8",
"@types/styled-components": "^5.1.11",
"@types/tar-stream": "^3.1.4",
"@types/tmp": "^0.2.6",
Expand Down
50 changes: 26 additions & 24 deletions extensions/ql-vscode/src/common/sarif-parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Log } from "sarif";
import { createReadStream } from "fs-extra";
import { connectTo } from "stream-json/Assembler";
import { Assembler } from "stream-json/assembler.js";
import { getErrorMessage } from "./helpers-pure";
import { withParser } from "stream-json/filters/Ignore";
import { ignore } from "stream-json/filters/ignore.js";

export async function sarifParser(
interpretedResultsPath: string,
Expand All @@ -11,20 +11,39 @@ export async function sarifParser(
// Parse the SARIF file into token streams, filtering out some of the larger subtrees that we
// don't need.
const pipeline = createReadStream(interpretedResultsPath).pipe(
withParser({
ignore.withParserAsStream({
// We don't need to run's `artifacts` property, nor the driver's `notifications` property.
filter: /^runs\.\d+\.(artifacts|tool\.driver\.notifications)/,
}),
);

// Creates JavaScript objects from the token stream
const asm = connectTo(pipeline);

// Returns a constructed Log object with the results of an empty array if no results were found.
// If the parser fails for any reason, it will reject the promise.
return await new Promise((resolve, reject) => {
let alreadyDone = false;
pipeline.on("error", (error) => {

// Creates JavaScript objects from the token stream
Assembler.connectTo<Log>(pipeline, {
onDone: (asm) => {
const log = asm.current;

// Do some trivial validation. This isn't a full validation of the SARIF file, but it's at
// least enough to ensure that we're not trying to parse complete garbage later.
if (log === null || log.runs === undefined || log.runs.length < 1) {
reject(
new Error(
"Invalid SARIF file: expecting at least one run with result.",
),
);
return;
}

resolve(log);
alreadyDone = true;
},
});

pipeline.on("error", (error: Error) => {
reject(error);
});

Expand All @@ -38,23 +57,6 @@ export async function sarifParser(
);
}
});

asm.on("done", (asm) => {
const log = asm.current;

// Do some trivial validation. This isn't a full validation of the SARIF file, but it's at
// least enough to ensure that we're not trying to parse complete garbage later.
if (log.runs === undefined || log.runs.length < 1) {
reject(
new Error(
"Invalid SARIF file: expecting at least one run with result.",
),
);
}

resolve(log);
alreadyDone = true;
});
});
} catch (e) {
throw new Error(
Expand Down
2 changes: 2 additions & 0 deletions extensions/ql-vscode/test/jest-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const transformPackages = [
"readdirp",
"rettime",
"robust-predicates",
"stream-chain",
"stream-json",
"universal-user-agent",
"until-async",
];
Expand Down