-
Notifications
You must be signed in to change notification settings - Fork 229
Fix large sarif handling #1004
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
Merged
aeisenberg
merged 10 commits into
github:main
from
marcnjaramillo:fix-large-sarif-handling
Nov 22, 2021
Merged
Fix large sarif handling #1004
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c49aa8e
Fix issue with large SARIF files crashing view
marcnjaramillo 4374f40
Add changelog entry and add missing dependencies
marcnjaramillo 6312923
Work on tests for new behavior
marcnjaramillo a666619
Remove error handling for now
marcnjaramillo ca5e5e2
Finish tests
marcnjaramillo c3eca5b
Update test for valid SARIF file
marcnjaramillo d53abd8
Make suggested changes, build currently failing
marcnjaramillo 0bb1501
Move sarif parser and tests, build completing
marcnjaramillo 9d9f48b
Fix tests for sarif parser
marcnjaramillo ad81127
Move test files into data directory
marcnjaramillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import * as Sarif from 'sarif'; | ||
| import * as fs from 'fs-extra'; | ||
| import { parser } from 'stream-json'; | ||
| import { pick } from 'stream-json/filters/Pick'; | ||
| import Assembler = require('stream-json/Assembler'); | ||
| import { chain } from 'stream-chain'; | ||
|
|
||
| const DUMMY_TOOL : Sarif.Tool = {driver: {name: ''}}; | ||
|
|
||
| export async function sarifParser(interpretedResultsPath: string) : Promise<Sarif.Log> { | ||
| try { | ||
| // Parse the SARIF file into token streams, filtering out only the results array. | ||
| const p = parser(); | ||
| const pipeline = chain([ | ||
| fs.createReadStream(interpretedResultsPath), | ||
| p, | ||
| pick({filter: 'runs.0.results'}) | ||
| ]); | ||
|
|
||
| // Creates JavaScript objects from the token stream | ||
| const asm = Assembler.connectTo(pipeline); | ||
|
|
||
| // Returns a constructed Log object with the results or 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) => { | ||
| pipeline.on('error', (error) => { | ||
| reject(error); | ||
| }); | ||
|
|
||
| asm.on('done', (asm) => { | ||
|
|
||
| const log : Sarif.Log = { | ||
| version: '2.1.0', | ||
| runs: [ | ||
| { | ||
| tool: DUMMY_TOOL, | ||
| results: asm.current ?? [] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| resolve(log); | ||
| }); | ||
| }); | ||
| } catch (err) { | ||
| throw new Error(`Parsing output of interpretation failed: ${err.stderr || err}`); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
extensions/ql-vscode/src/vscode-tests/no-workspace/data/sarif/emptyResultsSarif.sarif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "version": "2.1.0", | ||
| "$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.4", | ||
| "runs": [ | ||
| { | ||
| "tool": { | ||
| "driver": { | ||
| "name": "ESLint", | ||
| "informationUri": "https://eslint.org", | ||
| "rules": [ | ||
| { | ||
| "id": "no-unused-vars", | ||
| "shortDescription": { | ||
| "text": "disallow unused variables" | ||
| }, | ||
| "helpUri": "https://eslint.org/docs/rules/no-unused-vars", | ||
| "properties": { | ||
| "category": "Variables" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "artifacts": [ | ||
| { | ||
| "location": { | ||
| "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js" | ||
| } | ||
| } | ||
| ], | ||
| "results": [] | ||
| } | ||
| ] | ||
| } |
33 changes: 33 additions & 0 deletions
33
extensions/ql-vscode/src/vscode-tests/no-workspace/data/sarif/invalidSarif.sarif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "version": "2.1.0", | ||
| "$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.4", | ||
| "runs": [ | ||
| { | ||
| "tool": { | ||
| "driver": { | ||
| "name": "ESLint", | ||
| "informationUri": "https://eslint.org", | ||
| "rules": [ | ||
| { | ||
| "id": "no-unused-vars", | ||
| "shortDescription": { | ||
| "text": "disallow unused variables" | ||
| }, | ||
| "helpUri": "https://eslint.org/docs/rules/no-unused-vars", | ||
| "properties": { | ||
| "category": "Variables" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "artifacts": [ | ||
| { | ||
| "location": { | ||
| "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.