-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
Use annotations to configure rules in rules-complexity #3768
Conversation
The issue message had to be changed as the issue is used to extract the rule id which is used to lookup the threshold from the config.
Codecov Report
@@ Coverage Diff @@
## main #3768 +/- ##
============================================
- Coverage 83.52% 83.46% -0.07%
+ Complexity 2915 2900 -15
============================================
Files 452 452
Lines 8765 8749 -16
Branches 1665 1665
============================================
- Hits 7321 7302 -19
- Misses 542 545 +3
Partials 902 902 Continue to review full report at Codecov.
|
...es-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArguments.kt
Show resolved
Hide resolved
...complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LabeledExpression.kt
Outdated
Show resolved
Hide resolved
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.
Thanks for pushing this initiative forward. This really improves detekt's code base. No misuse of the comments anymore.
I have a few open questions.
- I guess the
generator
module also needs an update in order to output the correct website sources. Am I right? - Do we need any other updates to the documentation? I'm thinking about the
Contributing.md
in order to not mislead new contributors or users. Detekt's docs become outdated quite often. It's sometimes forgotten when introducing changes.
The |
Cool. I missed this, unfortunately. |
@@ -110,6 +112,6 @@ class ComplexCondition( | |||
} | |||
|
|||
companion object { | |||
const val DEFAULT_CONDITIONS_COUNT = 4 | |||
private const val DEFAULT_CONDITIONS_COUNT = 4 |
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.
Probably out of scope but I think that inline this values will improve the readability of this code.
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 point. I was afraid to trigger magic number violations but it seems to work
|
||
override val issue = Issue( | ||
"NamedArguments", | ||
Severity.Maintainability, | ||
"Function invocation with more than $threshold parameters must all be named", | ||
"Parameters of function invocation must all be named", |
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.
Can't we use the threshold? The description that you set here is not correct.
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.
That is a great catch. Unfortunately that is not possible. When threshold
is evaluated, the ruleId is used to lookup the config key. In order to get the ruleId, the issue is created. -> infinite loop
How about: "Prefer named arguments for functions to improve readability." This is semi-consistent with rules like ComplexInterface or ComplexCondition where only the general rule is described without mentioning the exact threshold.
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.
This is actually a bug today: Even if the threshold
in configuration is 4, the issue.description
will always be Function invocation with more than 3 parameters must all be named
because the existing description is reading value from the threshold
constructor argument.
This belongs to #3670 and replaces all configuration kdoc tags in
rules-complexity
with annotations. There are a few decisions to make:simple properties
fallback properties
transformed properties
I am fairly ambivalent about this and I don't know if that is something we even have to agree upon. I am curious about your thoughts.