Add SARIF output support.#4651
Conversation
2e352ed to
3395a1b
Compare
December 17, 2022 18:39
|
Thanks for your contribution. Without actually looking at what it does - please add some unit and/or system tests for it. |
Sorry, something went wrong.
|
I haven't looked into your implementation but I really like this. 👍 |
Sorry, something went wrong.
c75210c to
8c84999
Compare
December 19, 2022 19:38
|
@firewave, any idea how to include certain .cpp files into the Visual Studio build? I don't have any experience with Windows development. |
Sorry, something went wrong.
8ce527a to
8fdaa05
Compare
December 22, 2022 15:41
Currently, for XML output, the XML generation is tightly-coupled with the `ErrorMessage` class, which makes it harder to implement other formats (e.g. SARIF) that may need to see all of the errors/findings at once. Furthermore, implementing the serialization in the `ErrorMessage` class as individual methods (e.g. `toXML`) does not scale very well when using multiple formats. This approach uses the `AnalysisReport` abstract class to sub-class the different serialization formats.
This treats the CLI output as just another format (default) for the findings/report.
This should look and feel like the rest of the CppCheck code.
This is a good start, but it still needs some work. In particular, I need to fix the startLine/endLine/startColumn/endColumn part. Right now, I am using placeholder values ("1") instead of the real line/column numbers.
This matches the other AnalysisReport classes, and it's what clang-tidy recommends.
SARIF's precision property maps to Cppcheck's certainty, which is essentially the confidence level.
|
Sorry for the late reply but I currently out sick. So still no code review...
If #4652 is merged (could happen any day), |
Sorry, something went wrong.
|
Since GitHub actions apparently support SARIF output could also also adjust the selfcheck workflow to use SARIF output instead of relying on the exitcode? Also if SARIF is used should the exitcode be forced to 0? I have no idea how other tools implement this. |
Sorry, something went wrong.
firewave
left a comment
There was a problem hiding this comment.
Also run dmake to actually update the Makefile.
Sorry, something went wrong.
|
@firewave, unfortunately See https://github.com/mario-campos/cppcheck/actions/runs/3887481113/jobs/6633822871. Which means that, without tampering with the Makefile, |
Sorry, something went wrong.
…lue. We will only pass std::string by value if it can be std::move()d. Otherwise, it will get passed as a constant reference.
|
I think this looks really interesting. There are some refactorings I would like to see.. but maybe instead of writing lots of nits it's quicker to just take over the finishing touches.. |
Sorry, something went wrong.
I have the feeling that you can adjust dmake.cpp here: I guess it should say something like: |
Sorry, something went wrong.
I have made some fixes in this branch: https://github.com/danmar/cppcheck/tree/4651 The fixes I made are here: https://github.com/danmar/cppcheck/commit/acca98d8f33e8f1f4bb5e06c4fb88277970830a2.diff There are still some tests that fail. You can run those tests with these commands: If the tests are fixed I have the feeling that we can merge this PR. |
Sorry, something went wrong.
That would be helpful. Unfortunately, now that the holiday season is over, I don't have as much time for this PR as I did before. But, I will still continue to address the remaining problems as much as I can. |
Sorry, something went wrong.
|
FYI there's already an PR which adds that output format command-line switch: #3365. |
Sorry, something went wrong.
This has been on my TODO list for a while! I've been wanting to integrate CppCheck's results into GitHub since Code Scanning came out. To do that, however, the tool needs to spit out SARIF.
To test it out, run
cppcheck --output-format=sarif --quiet foo.cNow, this is only an initial stab, and it's probably a bit ugly. I'm not quite done just yet (hence why it's a draft PR). For one, it's not truly outputting the correct line/column numbers. So, if you have any suggestions or comments, please let me know.
Also, I initially tried to work SARIF output into the original design by adding a
ErrorMessage::toSARIFmethod (alaErrorMessage::toXML), but I quickly realized that this wouldn't work very well, since the SARIF document has to be "constructed", not "streamed" the way the XML document is. Which meant that I had to rework the way that findings ("errors") were collected and aggregated, since the SARIF document kinda needs to see everything all at once.