-
Notifications
You must be signed in to change notification settings - Fork 664
feat(rome_service): auto generate configuration for rules #2890
Conversation
a0b03dd
to
b4597e0
Compare
Deploying with Cloudflare Pages
|
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
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.
Interestingly, this raises the question of whether generating a static struct for the rules configuration is the best solution, compared for instance to deserializing the rules field to a HashMap<String, Box<RawValue>>
and letting the analyzer handle the deserialization of the inner data (the main advantage I see to doing that is the ability for the analyzer to emit a custom diagnostic for invalid configurations, eg. the rule "noDeadCode" does not exist, did you mean "js/noDeadCode" ?
)
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.
Looks good. I do have a few questions (and I like @leops point on the suggestions).
- Does Rome-classic support changing the warning level of a diagnostic?
- 'error' is likely not the right default for all lint rules, especially rules for which no sound static analysis is possible due to JS's dynamic nature. How do you intend rules that, by default, should emit warnings?
As we didn't discuss this and I kept the configuration from Rome classic. If we want to evaluate another approach, let's do it on another channel. As this is more an architecture discussion and not about the code, I followed up the discussion here: #2632 (reply in thread) I would like to evaluate the PR with this approach. We are always in time for changing it.
Rome was still behind and it didn't allow to turn off rules, unless using suppression comments. In this regard we are exploring new ground!
That's a nice question, and I don't have an answer yet. The thing is, for now all rules emit warnings or errors and we don't have a more finer way of doing that per rule, not ahead of time at least. Each rule emits a diagnostic and we can't know ahead of time which type, unless we execute them. |
One more question. How would this configuration format support rule specific configurations |
It doesn't support it and it hasn't been taken in consideration. We haven't discussed the possibility to have configuration per rule, and I believe it does go against the rome philosophy where we should have less configuration as possible. We can revisit the philosophy in a separated discussion. That would be a possible breaking change. |
I agree on the philosophy of providing good defaults and avoiding any unnecessary options. The philosophy could even be extended to not have support for overriding the lint rule level by arguing that we pick the appropriate defaults. I think it would be worth spending some time exploring configuration formats that support per-rule options to avoid a breaking change in the very near future OR at least go through the rules with planned and check if we can implement all of them without having per-rule option support. |
Absolutely, this is just something I thought about while reviewing this and wanted to raise a possible discussion about, but it's not an issue for merging this PR
This is something we can revisit in more detail once this configuration actually gets integrated with the analyzer, but it would be possible to make the severity on An alternative / complement to this would be to consider the
This way if a rule is not guaranteed to be sound it could emit a warning, and the diagnostic will still be emitted as a warning even if the rule is set to |
True, this is a good point. This is something we wanted to do time ago: #1529
This is part of #2741 , where we will evaluate rules that require a configuration and discuss them, and see how we can go from there. I don't mind breaking changes because we are still in |
@leops do you have any idea why the workflow for the codegen is failing? Can't understand why |
That's true but comes at the risk that other things will be more important in the upcoming 0.9 and then 10.0 release and we then missed our chance. That's why I think it would be valuable to invest a couple of minutes to post a few options on how we could support rule-specific options. For example, one option that isn't a breaking change is to define the rule value as |
I believe we can use a mixed approach using what clippy is doing, which by using a custom function to deserialize the rules. Clippy doesn't allow to turn off rules at configuration level though, you can only provide options to rules. Clippy uses macros to turn off rules in a global way. I will spend some time and propose a solution |
Summary
Closes #2887
This PR implements a way to auto generate the configuration of the
rome.json
of the rules using the metadata defined in each rule.The configuration, in this PR, is now shaped in this way:
There's a new field called
globals
. We will use this field to store global references to the root scope of the semantic model cc @xunilrjThere's a new field called
rules
which will contain the rules. The rules divided by groups. This all auto generate from the metadata, so it will change accordingly cc @leops .Each rule is defined by a
RuleConfiguration
, where we can:A rule is not serialized if it's configured to emit diagnostics, because it's the default. This could change if we will use a recommendation system.
Consuming these defaults is out of scope, this will be implemented in other PRs.
As for now, all the rules are enabled and their default is
RuleConfiguration::Error
, although since they are not consumed yet, it won't make a difference for now.The idea is to enable certain rules as "recommended", but this is also out of scope and it will be implemented in another PR.
I also fixed an error on the max diagnostics printer, the message was incorrectly emitted every time.
Test Plan
Because the configuration is not consume it yet, there's no practical test. I added for unknown field on the rule, which demonstrates that the configuration is correctly deserialized by
serde
.