-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add SARIF output format for report #4 #33
Conversation
9eb6a54
to
8116b62
Compare
It miss some property in order to be compatible with Github. I am going to add them. |
Added. The only thing missing is |
Thank you @Coruscant11! I will be looking at this soon.
Yes, good observation. The current Nosey Parker implementation saves its findings in a sqlite database, but the schema it uses was chosen for expedience rather than completeness of information. It doesn't record anything but the rule name for findings at present. So the approach you've taken is very reasonable. |
The More detail:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Coruscant11. Thanks for this contribution! This will help make Nosey Parker simpler to integrate into various workflows by supporting SARIF format.
Your code overall looks good to me, and I'm going to merge it back shortly.
I made a few small changes, which you can see in the commit log if you're curious of details. The most notable ones:
- I fixed the end column locations in the SARIF output. They were off by one character, due to a discrepancy in how Nosey Parker and the SARIF format represent ranges (closed intervals vs half-open intervals).
- I added additional byte offset location to the SARIF output. I don't think it hurts to include it also.
- I restructured the
sarif_format
function a bit to reduce nesting and simplify some error handling. (I don't really mind how big it is at present.)
Including it seems to confuse the VSCode SARIF Results Viewer at times. There is probably something not quite right about the locations.
I was just about to merge, but then noticed that VSCode's SARIF viewer extension was not working properly in some cases when Nosey Parker's SARIF output included byte-based ranges in addition to line+column-based ranges. I commented out that additional range information. Will revisit later. |
@Coruscant11 thanks again—Nice work! |
@bradlarsen Thank you too for your changes! Very interesting to see all things that I forgot. Will try to keep that in mind as much as possible in the future 😄 |
You didn't really forget anything—all good! |
Fixes #4
Hello 👋
Resources
https://github.com/microsoft/sarif-tutorials/
For this PR I used the crate
serde-sarif
.Documentation available here : https://docs.rs/serde-sarif/latest/serde_sarif/
And I took inspiration from this code.
Here is my PR. Feel free to tell me where I may have done something wrong! It is the first time that I try to contribute to another project. 😄
I tested on several report and everything should work.
The
sarif_format
function incmd_report.rs
is quite long. Is it an issue? Should I dispatch in multiple functions or not?Improvements
sarif
is to specify used rules. In my case I simply added all default rules of noseyparker in the file. We could add only used rules in order to save space. I know that rules names are available but I didn't find a way to efficiently found their associated regex, in the report code scope.Tools
Here is a tool allowing to try to read SARIF files : https://microsoft.github.io/sarif-web-component/
And there is also the VSCode extension
Sarif Viewer
: https://marketplace.visualstudio.com/items?itemName=MS-SarifVSCode.sarif-viewerExamples
I tried in several repositories, and everything seems ok.
Here is an example for CPython :
SARIF Template example for NoseyParker