-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #5525: [core] Add Sarif Level Property #5573
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
Conversation
adangel
left a comment
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.
Thanks for your PR!
Could you please also update the example on https://docs.pmd-code.org/latest/pmd_userdocs_report_formats.html#sarif ? The file to change is https://github.com/pmd/pmd/blob/main/docs/report-examples/pmd-report.sarif.json
Then I think, we should additionally add the property "defaultConfiguration" to "runs[0].tool.driver.rules[x]". There we can specify the default log level per rule. See https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141791100 and https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141791105 .
In theory, when we have such a default configuration, we wouldn't need the level property on each result, as the specification defines precisely how to derive the value (https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790898).
However, we could still keep it, as it makes it easier for the tools (e.g. VS Code's SARIF Viewer recognizes the defaultConfiguration, while IntelliJ's build-in Service-Side Analysis tool window doesn't seem to).
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Outdated
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java
Show resolved
Hide resolved
|
@adangel So I added the ReportingConfiguration as a Class to be used for the attribute "defaultConfiguration", but I need more information on what this should be filled with or where ^^' |
Let's start with "where": the defaultConfiguration property is part of the reportingDescriptor object - which is created when the SarifLogBuilder processes a rule violation at pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java Lines 44 to 46 in 901d976
That means, you need to create a new defaultConfiguration object here pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java Lines 170 to 179 in 901d976
However, before you can add it to the reportingDescriptor builder, you need to add the property "defaultConfiguration" to the ReportingDescriptor class along with a setter in the builder: pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java Line 2067 in 08fb81a
pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java Line 2119 in 08fb81a
The "what" is not so much different than what you already did: In getReportingDescriptor() you have access to the rule's priority setting via |
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Outdated
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Outdated
Show resolved
Hide resolved
Pankraz76
left a comment
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.
- Benefits of Fully Qualified Imports in Java
- we should consider using https://checkstyle.sourceforge.io/checks/whitespace/emptylineseparator.html
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Outdated
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Show resolved
Hide resolved
pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLog.java
Show resolved
Hide resolved
|
How is this PR going? I am interested in this change as well. Thanks. |
|
Compared to main: |
adangel
left a comment
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.
Thanks for the PR!
I'm going to fix one bug before I merge this: The enabled property of the defaultConfiguration should either be true or not specified at all. Currently it is false, which is irritating, as the report definitely contains a result for this rule but the rule seems to be disabled...
Describe the PR
Adding and filling the field for the severeness of a rule in the sarif report according to the defined priorities in the pmd ruleset.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)