-
Notifications
You must be signed in to change notification settings - Fork 650
feat(rome_service): support for recommendation of rules #2924
Conversation
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
31930e3
to
324dd8e
Compare
324dd8e
to
b80fd84
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.
The code building up the filter could be simplified by only creating the enabled_rules
list instead of both the enabled and disabled set (the information in disabled_rules
is redundant since those rules could simply not be included in the enabled set)
I can change the code generation, but now I have a question: why do we have Also, don't you think that having the disabled rules would able more features? An example that come up to my mind is the possibility to emit a warning when we find a suppression for a rule that was disabled in the configuration. |
These two filters solve different problems, the idea was that
This should already be the case, rules that are filtered out are not added to the |
d126c60
to
daeba2c
Compare
if self.is_recommended() { | ||
enabled_rules.extend(Js::RECOMMENDED_RULES); | ||
enabled_rules.extend(Jsx::RECOMMENDED_RULES); | ||
enabled_rules.extend(Regex::RECOMMENDED_RULES); | ||
enabled_rules.extend(Ts::RECOMMENDED_RULES); | ||
} |
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.
Do we have any validation of the configuration. Or what happens if the user sets recomended: true
but also has js: { recommended: 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.
Oh yeah, good point. I changed the code and added a test case. In your example we should enable all the recommended rules, exception for the recommended rules of the group js
.
Do we have any validation of the configuration
Only the one that belongs to serde during serialization/deserialization
}) | ||
} | ||
|
||
pub fn from_enabled_rules(enabled_rules: Option<&'analysis [RuleFilter<'analysis>]>) -> Self { |
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 you add some documentation why it is necessary to have enabled
and disabled
rules? The thing I'm concerned about the two filters is, what if enabled
and disabled
disagree about a particular rule. Is it then disabled or enabled?
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.
what if enabled and disabled disagree about a particular rule. Is it then disabled or enabled?
This is more a question for @leops
For now I reverted the change and limit myself only to enabled_rules
. I will optimize it later
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 exact semantic of the AnalysisFilter
is that a rule is included if it's present in the enabled_rules
(or this field is set to None
) and not present in disabled_rules
, this means if a rule is present in both sets it will be disabled
90b42f3
to
4e97bf9
Compare
Summary
Closes #2912
This PR enables a new feature in the configuration, which is the possibility to opt-in the recommended rules suggested by the Rome team.
Configuration changes
It's possible to opt-in rules in two different way:
De-serialization of rules
While we desarialize rules, we also validate that the rules we have in the configuration rules are valid for the current group. If not, we emit a
ConfigurationError
. We do so by saving an array of all the rules that belong to a certain group.The serialization is out of scope, because we don't have an use case yet. But the serialization will need to be custom, because we want to keep the order of the original map.
Code generation
All the new code (configuration shape, de-serialization and methods) are code generated from the metadata of the rules.
const
inside the struct, and they represented as an array ofRuleFilter
. The name of the rule is taken fromSelf::GROUP_RULES
, so we don't repeat the static stringsRules
has now a method calledas_analysis_filters
which will emit twoIndexSet
of enabled filters and disabled. The reason whyIndexSet
was used is because the enabled filters needs to be computed from the difference with the disabled filters. Here's an example:In this example we need pull all the recommended rules, but then we have to remove the rules that have been turned off.
IndexSet
allows us to do so with a simple.difference
function.Computation of
AnalysisFilter
Here's there have been some limitations, due to how
RuleFilter
is designed (all references), and because of that the creation of theAnalysisFilter
object must be done in place, right before being used. This caused a bit of repetition of code. If you have a solution to avoid this repetition of code, it would be greatTest Plan
I updated some existing test and added new ones, some happy path and error path.