Skip to content

Allow for undefined codeSnippets#1253

Merged
aeisenberg merged 6 commits intomainfrom
aeisenberg/codeSnippet-handling
Mar 31, 2022
Merged

Allow for undefined codeSnippets#1253
aeisenberg merged 6 commits intomainfrom
aeisenberg/codeSnippet-handling

Conversation

@aeisenberg
Copy link
Contributor

This reverts commit 006cc8c.

Allows for SARIF that has regions but no code snippets.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested review from a team as code owners March 29, 2022 20:12
@aeisenberg aeisenberg force-pushed the aeisenberg/codeSnippet-handling branch from 19a0bc7 to 6fa0227 Compare March 29, 2022 22:08
@aeisenberg aeisenberg force-pushed the aeisenberg/analysis-results-on-restart branch from de06ed1 to 8daa92a Compare March 29, 2022 23:04
Copy link
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

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

Thanks for extracting this out into its own PR, it's much easier to review!

Changes generally looking good to me, just a few small comments.

@@ -1,5 +1,4 @@
import * as path from 'path';
import * as fs from 'fs-extra';
Copy link
Contributor

Choose a reason for hiding this comment

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

What's going on here? Is this a bad merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes...it's fixed in main, but since this PR doesn't target main, I need to have the fix here as well.

}) => {

const code = codeSnippet.text.split('\n');
const code = codeSnippet?.text.split('\n') || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about returning early if the codeSnippet is undefined, instead of having to deal with it throughout? E.g.

if (!codeSnippet) {
  return (
     <Container>
       <TitleContainer>
         <Link href={titleFileUri}>{fileLink.filePath}</Link>
       </TitleContainer>
     </Container>
}

(and perhaps extract the title stuff in its own component (within the function) so it can be re-used.

I think that makes clearer what should happen if code snippet is not present. But that's ofc just my opinion 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes...good idea.

await arm.downloadAnalysisResults(remoteQueryResult0.analysisSummaries[1], () => Promise.resolve());

expect(await (arm as any).isDownloadedNotInMemory(remoteQueryResult0.analysisSummaries[0])).to.be.true;
expect(await (arm as any).isAnalysisDownloadedNotInMemory(remoteQueryResult0.analysisSummaries[0])).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

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

These look like artifacts of a bad merge

expect(actualCodeSnippet).to.deep.equal(expectedCodeSnippet);
});

it('should not return errors for result locations with no contextRegion', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('should not return errors for result locations with no contextRegion', () => {
it('should use highlightedRegion for result locations with no contextRegion', () => {

expect(msg.startsWith('Error when processing SARIF result')).to.be.true;
}

function expectNoParsingError(result: { errors: string[] | undefined }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The result returned by extractAnalysisAlerts is always guaranteed to return errors. I'm not sure why we're dealing with undefined here.

Isn't the check just expect(result.errors.length).to.equal(0)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes...undefined isn't an option here. I'll change that.

I was using expect(array.length, array.join()).to.equal(0); so that the second parameter to expect would print outt he actual array if there was an error. It was helpful earlier on while I was writing the test. And I decided to keep it since it's generally useful.

Base automatically changed from aeisenberg/analysis-results-on-restart to main March 31, 2022 14:19
@aeisenberg aeisenberg merged commit 2f79087 into main Mar 31, 2022
@aeisenberg aeisenberg deleted the aeisenberg/codeSnippet-handling branch March 31, 2022 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants