-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Support configurable severity per ruleset/rule in XML and Sarif output #3310
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3310 +/- ##
============================================
- Coverage 80.34% 80.27% -0.08%
+ Complexity 2724 2723 -1
============================================
Files 445 445
Lines 8177 8193 +16
Branches 1555 1558 +3
============================================
+ Hits 6570 6577 +7
- Misses 774 778 +4
- Partials 833 838 +5
Continue to review full report at Codecov.
|
I also realized that the severity, for now, is only in XML + Sarif. We are not differentiating severities in HTML or console output. If this is a good idea, please react to this comment so I will open a new issue for supporting them.
|
I agree with all except html. I don't think that we should change all the background. We could use a label and only change that label color. |
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.
Looks good!
Anyhow, a refactoring would be great in separate PR in order to implement the severity levels properly and keep the architecture tidy. Then there's no need for copying stuff around and no risk to introduce cyclic dependencies with future refactorings.
We can break such cycling dependency by refactoring, but I would prefer doing so in the next PR where we can remove the existing Severity and replace it with the new SeverityLevel.
+1 great |
#3127 prototyped a new Rule API, which is much cleaner, but also not backward compatible. In order to keep the severity within every I have seen Detekt 2.0 mentioned in a few issues. Do we know when and how we are planning this? I imagine there will be a separate 2.0 branch where we can merge all breaking changes. |
At the moment those PRs are tagged in the milestone field with the corresponding detekt version. |
We talk a lot about 2.0 but we don't have the list of things that we want to change. So I'm not sure about creating a new branch. #3127 pretends to be retrocompatible. I mean, the idea is to deprecate the old api and keep it until 2.0. |
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.
Implementation looks good!
I think this could be backwards compatible for 1.x, please see my two comments below.
I also added a comment to our 2.0 ticket - #2680 (comment)
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/Findings.kt
Outdated
Show resolved
Hide resolved
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.
Great PR! I'm just a bit concerned about the compatibility.
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt
Outdated
Show resolved
Hide resolved
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt
Outdated
Show resolved
Hide resolved
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt
Outdated
Show resolved
Hide resolved
This PR also depends on #3320 |
detekt-report-sarif/src/test/kotlin/io/github/detekt/report/sarif/SarifOutputReportSpec.kt
Outdated
Show resolved
Hide resolved
#3310) * Support configurable severity per rule * Change default severity to warning and add default impl for Findings API * Add secondary constructor to maintain binary compatibility * Implement severity with backing properties with internal set * Revert some of the changes in CodeSmell * Fix detekt failure * Fix another detekt failure * Rebase onto master * Remove SeverityLevel.ignore * Dump API
Summary
This PR implements configuring the severity in the XML and Sarif output, which is the first step to implement #3274. The implementation is also different from #3306, because the severity in the configuration can only be a simplified version and does not allow custom strings.
Implementation
Adding the
severity
as a property ofIssue
does not work: Each rule initializes theissue
first then uses theissue.id
to initializeruleConfig
. If we want to useruleConfig
to parseseverity
, it has to be done afterissue
is created.We can break such cycling dependency by refactoring, but I would prefer doing so in the next PR where we can remove the existing
Severity
and replace it with the newSeverityLevel
.The choice here is to add the
severity
as a property ofFinding
, which is appended at the end to mitigate incompatibility. However, sinceFinding
and its children are not data class, I need to createcopyWithSeverity
to override the given severity.Followup
I did not deprecate or remove
Severity
,maxIssues
,warningsAsErrors
in this PR. If this is a good time to do so, I would be happy to do those in a follow-up PR.Test
In addition to the unit test, I also performed an integration test in a different repo. Users can configure severity at ruleset level and rule level.