Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support SARIF format #1102

Closed
chao2zhang opened this issue Mar 11, 2021 · 10 comments
Closed

Support SARIF format #1102

chao2zhang opened this issue Mar 11, 2021 · 10 comments

Comments

@chao2zhang
Copy link
Contributor

Github has the capabilitiy to integrate third-party static analysis tools. The official documentation can be found here which requires static analysis tools to produce [SARIF] format.

This issue is already picked up in

I would like to seek your opinion on supporting SARIF format as first-class for ktlint. (We already have json format https://github.com/pinterest/ktlint/tree/master/ktlint-reporter-json).
If approved, I would be happy to contribute as well.

@Tapchicoma
Copy link
Collaborator

So it is basically adding another reporter that will produce report in SARIF format?

@chao2zhang
Copy link
Contributor Author

That's correct.

@chao2zhang
Copy link
Contributor Author

Because SARIF is officially supported by Github code action, we could show the violations inline (https://github.com/chao2zhang/detekt/pull/9/files)
image

@Tapchicoma
Copy link
Collaborator

Then it makes sense to add such reporter. Feel free to contribute 👍

@Tapchicoma
Copy link
Collaborator

@chao2zhang do you plan to further improve SARIF format support or it is fine as it is?

@chao2zhang
Copy link
Contributor Author

We can close this issue since we have basic support. Further improvements can be done in separate issues:

  • SarifSchema210.runs[0].tool.driver.rules is empty for now. Ideally, this should be a list of rules that were active in the current run. I will address this in a follow-up PR since this requires refactoring.
  • I have not yet added other information like autoCorrected or autoCorrectible in the output.
  • Potentially we can also add github workflow setup in the documentation. There are other community projects that does this so this is optional to me.

@orchestr7
Copy link
Contributor

orchestr7 commented Feb 1, 2022

@chao2zhang have you tested ktlint reports in GitHub? It looks like the calculation of URI paths is incorrect, I was not able to make it work with out ktlint plugins...

Any examples, where it works?

@orchestr7
Copy link
Contributor

orchestr7 commented Feb 2, 2022

Got it working somehow. But definitely need to customise plugins properly for it. Github is not able to work with absolute paths and that is a big problem for everyone - in ktlint we need to set user.home for it.

telegram-cloud-photo-size-2-5465232106637604469-y

@romtsn
Copy link
Collaborator

romtsn commented Feb 2, 2022

@akuleshov7 send PR?

@orchestr7
Copy link
Contributor

orchestr7 commented Feb 2, 2022

@akuleshov7 send PR?
@romtsn

Рома, we are supporting it in maven and gradle plugins for our diktat ruleset. Here is some small test:
https://github.com/analysis-dev/diktat/pull/1205/files

see: diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt

The idea is the following: the user adds a special flag githubActions to the plugin and get everything out of the box.
So I guess this logic should be copied to your plugins as well.

As soon as I will finish with diktat - I will move the logic to your plugins.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants