Implement ignoreAnnotated as a core feature - #4102
Conversation
9cdebfe to
671f4de
Compare
064a17e to
4c4e217
Compare
Codecov Report
@@ Coverage Diff @@
## main #4102 +/- ##
============================================
+ Coverage 83.45% 83.46% +0.01%
+ Complexity 3185 3177 -8
============================================
Files 463 465 +2
Lines 9095 9103 +8
Branches 1768 1774 +6
============================================
+ Hits 7590 7598 +8
Misses 571 571
Partials 934 934
Continue to review full report at Codecov.
|
1b63c10 to
89f989d
Compare
89f989d to
51a9a76
Compare
cortinico
left a comment
There was a problem hiding this comment.
Great work! I believe on the discoverability we can just have a page in the documentation and link it in the release notes
marschwar
left a comment
There was a problem hiding this comment.
I like where this is headed.
| } | ||
|
|
||
| private fun filterSuppressedFindings(rule: BaseRule): List<Finding> { | ||
| val suppressors = getSuppressors(rule) |
There was a problem hiding this comment.
If I read this correctly, the list of suppressors would be generated for each and every file even though it only depends on the rule. This will create a lot of unnecessary objects in the process.
There was a problem hiding this comment.
Yes. But the same happens right now with the rules. We create all the rules for each file. Changing this is a big refactor. It will be fixed in 2.0
80cb167 to
4135639
Compare
4135639 to
1269026
Compare
| */ | ||
| typealias Suppressor = (Finding) -> Boolean | ||
|
|
||
| internal fun getSuppressors(rule: BaseRule): List<Suppressor> { |
There was a problem hiding this comment.
We only have one Suppressor instance in the returned list - Would you consider using the decorator pattern in case we have more Suppressors or use List<Suppressor>?
There was a problem hiding this comment.
I don't know what do you mean by "decorator pattern".
Right now there is only one suppressor but my idea is to have more once we merge this. There is a short list of examples at #4068
There was a problem hiding this comment.
open abstract class Suppressor : Predicate<Finding> {
}
operator fun Suppressor.plus(suppressor: Suppressor): Suppressor {
return object : Suppressor() {
override fun test(t: Finding) = this@plus.test(t) || suppressor.test(t)
}
}
object DefaultSuppressor : Suppressor() {
override fun test(t: Finding) = true
}
I meant like this where we can compose suppressors in a chain (Probably should be called as a chain of responsibility). The benefit of so is that we can simplify the suppressor implementation that to the Analyzer, the suppressor function is always a simple function (Finding) -> Boolean.
There was a problem hiding this comment.
I think that I prefer to handle this as a List. The good part is that all of these isn't an public API so we could change it if we see problems with the current implementation.
1269026 to
632a219
Compare
632a219 to
1378a90
Compare
1378a90 to
1a8f3d8
Compare
|
Hello! Are there any plans on releasing a new version of detekt with this change? |
I guess we can kickoff the |
Discussion here: #4068
This id the first step for a more advance way of suppress findings. It implements the most common request one and probably the easiest:
ignoreAnnotated. And I implemented it in a way that adding more should be easy.The main problem that I see with this implementation is the discoverability. As an user this is an interesting feature but it is really difficult to find it. For sure we should add somerhing in our documentation but I think that it would not be enought. Any ideas here?
In this PR I'm removing some default values. For that reason I created #4101 before. We don't want those default values, they are library specific.
And I changed
LongParameterLista bit too. It was using the same configuration to do two things: 1) ignore a function completely for an annotation and 2) ignore the annotated parameter for the total count. So I removed the first part of that feature to relay on the common one and changed the second one to useignoreAnnotatedParameterinstead ofignoreAnnotated. This is a breaking change.Right now I'm just treating the annotations as a name, I'm not using the full qualifier. Do you think that it is necesary to do that? I think that we could keep it like this for now and we could change it later if someone miss that. We should not have problem extending it.
Closes #2231
Closes #4062