-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
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
- Throwable Could 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. |
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.
PR looks great to me!
...r/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/collection/ConfigurationCollector.kt
Show resolved
Hide resolved
...r/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/collection/ConfigurationCollector.kt
Outdated
Show resolved
Hide resolved
...r/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/collection/DocumentationCollector.kt
Show resolved
Hide resolved
...r/src/main/kotlin/io/gitlab/arturbosch/detekt/generator/collection/DocumentationCollector.kt
Outdated
Show resolved
Hide resolved
...erator/src/test/kotlin/io/gitlab/arturbosch/detekt/generator/collection/RuleCollectorSpec.kt
Outdated
Show resolved
Hide resolved
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally inline 15.. I guess that's violated by the MagicNumber 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.
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
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.
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
@Configuration
annotation on properties in conjunction with a config delegate.Advantages
valueOrDefault
as this is done by the delegate automaticallyLimitations / Points to discuss
ComplexMethod
to illustrate what it would look like.default-detekt-config.yml
is inconsistent ([run, let, apply]
vs.['**/test/**', '**/androidTest/**']
) so I opted for the version with quotes. Is that a problem?@Configuration
as they are not needed IMO.