-
-
Notifications
You must be signed in to change notification settings - Fork 797
Implement ignoreAnnotated as a core feature #4102
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
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
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 work! I believe on the discoverability we can just have a page in the documentation and link it in the release notes
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.
I like where this is headed.
@@ -136,6 +137,15 @@ internal class Analyzer( | |||
} | |||
} | |||
|
|||
private fun filterSuppressedFindings(rule: BaseRule): List<Finding> { | |||
val suppressors = getSuppressors(rule) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Show resolved
Hide resolved
80cb167
to
4135639
Compare
...ore/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/AnnotationSuppressorSpec.kt
Outdated
Show resolved
Hide resolved
4135639
to
1269026
Compare
detekt-core/src/test/resources/configs/config-value-type-correct-ignore-annotated.yml
Outdated
Show resolved
Hide resolved
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/SupressorsSet.kt
Outdated
Show resolved
Hide resolved
...complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt
Show resolved
Hide resolved
...ore/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/AnnotationSuppressorSpec.kt
Outdated
Show resolved
Hide resolved
*/ | ||
typealias Suppressor = (Finding) -> Boolean | ||
|
||
internal fun getSuppressors(rule: BaseRule): List<Suppressor> { |
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.
We only have one Suppressor
instance in the returned list - Would you consider using the decorator pattern in case we have more Suppressor
s or use List<Suppressor>
?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
LongParameterList
a 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 useignoreAnnotatedParameter
instead 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