+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_analyze): accept options inside analyzer #3325

Merged
merged 4 commits into from
Oct 5, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Oct 4, 2022

Summary

Closes #3324

This PR starts the works needed to implement "options" or "configuration" for the analyzer. The reason why I used the term "option" is because is in line with the formatter terminology.

As highlighted in the umbrella issue, I decided to split the work in different stages to make the implementation of the feature progressive. There are many changes that we have to do, and I felt that needed to be split in multiple stages.

This PR adds a new AnalyzerOptions struct which, for now, will contain two information:

  • globals, which are derived - for now - by Configuration::javascript::linter::globals. In the future this will be computed based on the language
  • rules, which is derived from the configuration of the rules - the rome.json file essentially - that match RuleSettings. At the moment the logic that computes the rules is hardcoded. Ideally this will have to be auto generated for each group. I will do such in another PR. rules is an HashMap mapped like this: "name of the rule" => Box<RawValue>. In order to use RawValue, I had to add serde_json as dependency. I tried to use Box<impl Any>, but unfortunately RawValue doesn't play well with Any because RawValue doesn't have a size that the compiler can know at compile time.
  • the analyze function now needs an &options as additional parameter

Test Plan

The logic of the analyzer slightly changed, but it should only a compile time change and the rest of the existing tests should pass.

@ematipico ematipico requested a review from a team October 4, 2022 16:20
@ematipico ematipico temporarily deployed to netlify-playground October 4, 2022 16:20 Inactive
@netlify
Copy link

netlify bot commented Oct 4, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit c66f830
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/633d7df028b20d0008566fc0

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44939 44939 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1621 1621 0
Failed 4325 4325 0
Panics 0 0 0
Coverage 27.26% 27.26% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12395 12395 0
Failed 3862 3862 0
Panics 0 0 0
Coverage 76.24% 76.24% 0.00%

@ematipico ematipico temporarily deployed to netlify-playground October 4, 2022 16:29 Inactive
@@ -13,6 +14,7 @@ where
query_result: &'a RuleQueryResult<R>,
root: &'a RuleRoot<R>,
services: RuleServiceBag<R>,
options: &'a AnalyzerOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could store the options in the service bag, it could make the change simpler than having to add it as a parameter or field on all the intermediate functions and data structures

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding it to the ServiceBag involves another series of changes around various traits. Inside RuleContext, services has a trait bound to RuleServiceBag.

I think we can do this change, but I would prefer to defer it to later for two reasons:

  • I am not comfortable with this kind of change
  • options will become a trait itself too - while rules are language agnostic, globals are not; so it seems more appropriate to make this change together with this one

/// }
/// }
/// ```
pub fn rule_options<F: FnOnce(&RuleOptions) -> ToType, ToType>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice since the RuleOptions is a thin wrapper around a RawValue the only way to get a value out of it will be through deserialization, so this function could simply require ToType: Deserialize<'de> (with the function borrowing self as &'de self) and remove the mapper argument.

Also for ease of use it would be nice to alias this function on the RuleContext with the rule_name automatically injected, so that most rules could simply write ctx.rule_options::<OptionsType>() and get the appropriate configuration entry back automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the intended final design, but we are not there yet, and that's why I decided to break down the work in multiple tasks:

  • using Deserialize requires having serde as a non-optional dependency, which is not a change we can do lightly (it creates errors)
  • we can't get the rule name yet, there are changes that needs to be implemented

@ematipico ematipico force-pushed the feature/analyzer-options branch from d95dbaf to b7ef59d Compare October 5, 2022 09:49
@ematipico ematipico temporarily deployed to netlify-playground October 5, 2022 09:50 Inactive
@ematipico ematipico force-pushed the feature/analyzer-options branch from b7ef59d to 914cf1d Compare October 5, 2022 09:50
@ematipico ematipico requested a review from leops October 5, 2022 09:50
@ematipico ematipico temporarily deployed to netlify-playground October 5, 2022 09:50 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 5, 2022 10:11 Inactive
@ematipico ematipico force-pushed the feature/analyzer-options branch from 9e2560e to c66f830 Compare October 5, 2022 12:51
@ematipico ematipico temporarily deployed to netlify-playground October 5, 2022 12:52 Inactive
@ematipico ematipico merged commit cca8f95 into main Oct 5, 2022
@ematipico ematipico deleted the feature/analyzer-options branch October 5, 2022 13:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create a new AnalyzerOptions data structure inside rome_analyze
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载