Rule Configuration using annotations#3637
Conversation
d595335 to
5450dab
Compare
I don't know how to help you here. Are there a lot of these cases? Could we simplify them to use always values in the same file?
This is not a problem at all. I was wondering about other configurations where we use this syntax: exceptionNames:
- ArrayIndexOutOfBoundsException
- Error
- Exception
- IllegalMonitorStateException
- NullPointerException
- IndexOutOfBoundsException
- RuntimeException
- ThrowableCould it be possible to use both? I mean, the one-line syntax in this example would be really difficult to maintain and works really bad with But again this don't need to be faced in this PR if it makes it more complex. |
Codecov Report
@@ Coverage Diff @@
## main #3637 +/- ##
============================================
- Coverage 77.97% 77.95% -0.02%
- Complexity 2837 2870 +33
============================================
Files 467 470 +3
Lines 9139 9245 +106
Branches 1737 1761 +24
============================================
+ Hits 7126 7207 +81
- Misses 1071 1077 +6
- Partials 942 961 +19
Continue to review full report at Codecov.
|
|
I don't think there are many cases where the default is defined outside the rule class itself. I don't see this as a huge problem as of know. List format: Maybe it always should be the line-per-item syntax for all list parameters? |
71fd3d0 to
7233c4e
Compare
I'm not sure about this either. We have some configurations that will probably never change ( |
|
Could someone confirm that I have left comments before on this PR? Instead of |
|
As far as I know you had not commented on this PR but rather #3608. I created an entirely new PR. I probably should have referenced it in the description. I did force push multiple times after rebasing onto master. |
| class ComplexMethod(config: Config = Config.empty) : Rule(config) { | ||
|
|
||
| @Configuration("McCabe's Cyclomatic Complexity (MCC) number for a method.") | ||
| private val threshold: Int by config(DEFAULT_THRESHOLD_METHOD_COMPLEXITY) |
There was a problem hiding this comment.
I would personally inline 15.. I guess that's violated by the MagicNumber rule.
There was a problem hiding this comment.
I am torn. I really think it is redundant since it is clearly the default value and does not need extra naming. But on the other hand I dislike us excessively suppressing our own rules.
To make this work, the annotation needs to be available at runtime.
Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
448e943 to
055c2f7
Compare
BraisGabin
left a comment
There was a problem hiding this comment.
And after this we need to make the migration and then remove the old code. Are you traking the remaining taask somewhere? I could help you with this more "mechanical" work.
|
And, of course, this is a huge improvement! |
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
What would be a good format for this? Create an issue per task or one for all? |
That's your call. Both seem fine to me. |
This PR relates to #3562 and makes it possible to configure a Rule using a
@Configurationannotation on properties in conjunction with a config delegate.Advantages
valueOrDefaultas this is done by the delegate automaticallyLimitations / Points to discuss
ComplexMethodto illustrate what it would look like.default-detekt-config.ymlis inconsistent ([run, let, apply]vs.['**/test/**', '**/androidTest/**']) so I opted for the version with quotes. Is that a problem?@Configurationas they are not needed IMO.