-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix --only-rule
config issues
#5773
Fix --only-rule
config issues
#5773
Conversation
Generated by 🚫 Danger |
39d5e73
to
f21a455
Compare
fcc3e1d
to
e7abb8a
Compare
635bce7
to
8fcdf52
Compare
2620ae0
to
a4d2e1f
Compare
c860708
to
f3014c7
Compare
f3014c7
to
64ebe80
Compare
@@ -26,6 +26,10 @@ public extension Configuration { | |||
/// Only enable the rules explicitly listed. | |||
case only(Set<String>) | |||
|
|||
/// Only enable the rule explicitly listed on the command line. The rule may have multiple identifiers, | |||
/// hence why this is represented as a Set |
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.
/// hence why this is represented as a Set | |
/// hence why this is represented as a set. |
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've changed this one and the one above to clarify the difference between onlyRules
and onlyRule
/// Only enable the rules explicitly listed in the configuration files.
case only(Set<String>)
/// Only enable the rule explicitly listed on the command line (and it's aliases).
case onlyRule(Set<String>)
It would be nice if the naming reflected that a bit more, but I don't have any good suggestions.
onlyRulesRuleIdentifiers = validate(ruleIds: onlyRulesRuleIdentifiers, valid: validRuleIdentifiers) | ||
resultingRules = allRulesWrapped.filter { tuple in | ||
onlyRulesRuleIdentifiers.contains(type(of: tuple.rule).description.identifier) | ||
}.map(\.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.
Can we avoid duplicating the code from the previous case? Does Swift allow case var .a(x), .b(x)
?
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 weirdly
case var .only(onlyRulesRuleIdentifiers), var .onlyRule(onlyRulesRuleIdentifiers):
customRulesFilter = { onlyRulesRuleIdentifiers.contains($0.identifier) }
onlyRulesRuleIdentifiers = validate(ruleIds: onlyRulesRuleIdentifiers, valid: validRuleIdentifiers)
resultingRules = allRulesWrapped.filter { tuple in
onlyRulesRuleIdentifiers.contains(type(of: tuple.rule).description.identifier)
}.map(\.rule)
would not compile for me. It did not like the onlyRulesRuleIdentifiers = validate(ruleIds: onlyRulesRuleIdentifiers, valid: validRuleIdentifiers)
line. Digging into that a little separately.
but this works:
case let .only(onlyRulesRuleIdentifiers), let .onlyRule(onlyRulesRuleIdentifiers):
customRulesFilter = { onlyRulesRuleIdentifiers.contains($0.identifier) }
let onlyRulesRuleIdentifiers = validate(ruleIds: onlyRulesRuleIdentifiers, valid: validRuleIdentifiers)
resultingRules = allRulesWrapped.filter { tuple in
onlyRulesRuleIdentifiers.contains(type(of: tuple.rule).description.identifier)
}.map(\.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.
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.
Oh, that means the Swift 5 compiler crashes while the Swift 6 compiler builds it just fine?
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 was my reading of it as well.
@@ -101,6 +104,9 @@ public extension Configuration { | |||
case let .only(onlyRules): | |||
return .only(Set(onlyRules.map(aliasResolver))) | |||
|
|||
case let .onlyRule(onlyRules): | |||
return .onlyRule(Set(onlyRules.map(aliasResolver))) |
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 .onlyRule
case having multiple identifiers associated looks confusing. It's only here, when the aliases come into the game. Could we map to .only
here instead and forget about .onlyRule
from now on?
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 that would be nicer, and the original code tried to implement --only-rule
via .only
. The problem is that when we're merging any later configurations, generally we want --only-rule
to override them, as it's been specified on the command line, whereas with only_rules
, the child configuration should take precedence.
Totally agree about the multiple identifiers - I do have a follow-on PR that allows --only-rule
to be specified multiple times on the command line, to enable multiple rules, so it's slightly more understandable in that context.
It would be better if the naming were clearer - both allEnabled
and onlyRule
are really command line options, and it would be nice if their naming captured that somehow, or at least if onlyRule
was somehow more distinctive, but I don't have any elegant suggestions.
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 see. Perhaps we could be more specific with the mode names having for example .defaultConfiguration
, .onlyConfiguration
, .onlyCommandLine
and .allCommandLine
.
Allowing multiple --only-rule
command line arguments makes it more reasonable that .onlyRule
takes a set of IDs. Let's document that at its declaration as well.
e708342
to
7a01856
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.
Very much looking forward to get this!
Addresses #5711, where if there was no default configuration file,
--only-rule
would be ignored.Replaces #5725
Previously,
--only-rule some_rule
was implemented as though the configuration was:This did not interact well when the top level configuration was absent, or with child configurations.
This PR adds a new
RulesMode
enum - to represent--only-rule
:onlyCommandLine
, and the other enums have been renamed to make it clearer whether they are derived from the configuration file or the command line.This allows interactions with child configurations to be applied correctly.
Like
.allCommandLine
(previouslyallEnabled
), rules enabled with--only-rule
can still be disabled in a child configuration, so if there are specific directories that the rule should not run on, that is supported. This may be useful when using--fix
with--only-rule
Additionally,
--only-rule
can now be specified more than once, to enable multiple rules