-
-
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
Run same rule multiple times with different configuration #7263
base: main
Are you sure you want to change the base?
Conversation
The output has rule ids like |
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 really like this :D
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Outdated
Show resolved
Hide resolved
config/detekt/detekt.yml
Outdated
@@ -1,3 +1,6 @@ | |||
config: | |||
validation: false |
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.
Why this?
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.
The validation code doesn't know about this type of config keys yet. I need to implement that. I disabled it just to make it work for now. As I said this is still not ready to merge. I just wanted to share it to show that this is near to be done.
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/Rule.kt
Outdated
Show resolved
Hide resolved
Indeed. Copy&paste error. I fixed it now. |
fe4a059
to
b4e7660
Compare
ba4ad98
to
1667d70
Compare
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/SingleRuleProvider.kt
Fixed
Show fixed
Hide fixed
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.
detekt found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
1667d70
to
d4db32d
Compare
d325745
to
d570d28
Compare
d570d28
to
ab77c23
Compare
ab77c23
to
e438dbc
Compare
e438dbc
to
8b42dd9
Compare
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Fixed
Show fixed
Hide fixed
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Fixed
Show fixed
Hide fixed
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7263 +/- ##
============================================
- Coverage 84.50% 84.50% -0.01%
- Complexity 4160 4163 +3
============================================
Files 572 572
Lines 11890 11902 +12
Branches 2461 2465 +4
============================================
+ Hits 10048 10058 +10
- Misses 590 591 +1
- Partials 1252 1253 +1 ☔ View full report in Codecov by Sentry. |
8b42dd9
to
72dfe9a
Compare
72dfe9a
to
41ea7be
Compare
@detekt/maintainers This PR is ready to review and I think that this one should get multiple eyes on it. |
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.
LGTM 👍 We need docs for this also :)
@@ -145,6 +154,11 @@ internal class Analyzer( | |||
} | |||
} | |||
|
|||
internal fun extractRuleName(key: String): Rule.Name? = | |||
runCatching { Rule.Name(key.split("/", limit = 2).first()) }.getOrNull() |
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.
Is there a way to get better DX here? In what cases can this throw and return null? If I read it correctly it'll simply ignore the rule. Should we fail when config is incorrect rather than let the user scratch their head why things are "not working". I guess the Rule.Name validation was there before, but now the runCatching can fail due to 2 reasons. Consider to get back "original" behavior:
runCatching { Rule.Name(key.split("/", limit = 2).first()) }.getOrNull() | |
val name = key.split("/", limit = 2).first() | |
return runCatching { Rule.Name(name) }.getOrNull() |
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.
Are we not allowing /
in original rule id? Also instead of runCatching { Rule.Name(key.split("/", limit = 2).first()) }.getOrNull()
can we do Rule.Name(key.split("/", limit = 2).firstOrNull()
active: true | ||
WildcardImport: | ||
active: true | ||
WildcardImport/extra: |
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 the wrong place to flag it, but wanted to start a thread.)
Is this syntax suppress-compatible, i.e. can I suppress a specific instance of a rule? Can IDEA handle it?
Will this work and only suppress the extra
instance?
@file:Suppress("WildcardImport/extra")
Will this work and suppress all the instances?
@file:Suppress("WildcardImport")
How can I suppress only the default instance, and not the extras?
@file:Suppress("WildcardImport/default")
(Same for baseline)
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.
@file:Suppress("WildcardImport")
This only suppress the default one (if it exists)
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.
So there's no syntax to suppress all of them? (e.g. if there's 3 set up, and all 3 flag the same thing, need to list 3 IDs?)
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. It you can give them the same alias to those 3 and use that.
I don't see a real scenario where suppressing all the rules of the same name is a good idea. But if someone end up with an issue like that we could implement wildcards RuleName/*
or something like that. But I prefer not to do that until a real use case appears.
@@ -62,6 +62,6 @@ interface RulesSpec { | |||
/** | |||
* Run a single rule. | |||
*/ | |||
class RestrictToSingleRule(val ruleSetId: RuleSet.Id, val ruleName: Rule.Name) : RunPolicy() | |||
class RestrictToSingleRule(val ruleSetId: RuleSet.Id, val ruleId: String) : RunPolicy() |
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.
Could this be a value-class that is pre-split, or at least hides the complexity of split("/", 2).first()
in a val ruleName: Rule.Name get() =
?
class RestrictToSingleRule(val ruleSetId: RuleSet.Id, val ruleId: String) : RunPolicy() | |
class RestrictToSingleRule(val ruleSetId: RuleSet.Id, val ruleId: Rule.Id) : RunPolicy() |
yamlConfigFromContent( | ||
""" | ||
custom: | ||
MaxLineLength/foo: |
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.
one TC should be there with MaxLineLength/foo/bar
and one with MaxLineLength/
(no value after /
) I think latter should be error in validation
With this PR we finally are able to run the same run multiple times with different configurations.
The most important part to discuss, I think, is if we like how those new instances are configured.
Right now if you want to create a new instance of the same rule you should add on your
detekt.yml
something like this:Close #6738