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. |
schalkms
left a comment
There was a problem hiding this comment.
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.
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)
8d03d9f to
0fa3206
Compare
BraisGabin
left a comment
There was a problem hiding this comment.
Great PR! I'm just a bit concerned about the compatibility.
4eef8de to
bf51683
Compare
|
This PR also depends on #3320 |
568dc98 to
afcab04
Compare
#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
severityas a property ofIssuedoes not work: Each rule initializes theissuefirst then uses theissue.idto initializeruleConfig. If we want to useruleConfigto parseseverity, it has to be done afterissueis 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
Severityand replace it with the newSeverityLevel.The choice here is to add the
severityas a property ofFinding, which is appended at the end to mitigate incompatibility. However, sinceFindingand its children are not data class, I need to createcopyWithSeverityto override the given severity.Followup
I did not deprecate or remove
Severity,maxIssues,warningsAsErrorsin 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.