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

feature(rome_js_analyzer): semantic rules and "no arguments" lint rule #2807

Merged
merged 15 commits into from
Jul 5, 2022

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Jul 1, 2022

This PR creates the foundation and implements the first semantic/scoping rule of #2743. Undoubtedly the SemanticModel will need improvements. We can do them as we see need from the rules.

Relevant changes

Query return node directly

 let node = ctx.query(); //instead of  let Ast(node) = ctx.query();

Semantic model is accessed through RuleContext

but the method model() exist only if the Rule asked for the semantic model.

let reference = ctx.query();

let name = reference.syntax().text_trimmed();
if name == "arguments" {
    let model = ctx.model();
    ...
}

New query type

Rules can ask to run with the semantic model with

type Query = Semantic<JsReferenceIdentifier>;

rome_js_analyze run the in two phases

Today everything is run serially. But the opportunity to run in MT is right there!
I did a quick test and the only major problem I saw was Rc inside rome_rowan.

pub fn analyze<F, B>(...) {
    // Phase Syntax
    // Phase Semantic
}

performance

Speed is almost the same without the semantic model. I saw a minor increase (1/2ms) in the input.js of the rome_cli folder.

As soon as we land more semantic lint rules, we can focus on optimization.

playground

I added two small improvements to the playground.
First, colors!

image

Second, timing:

this time in on the debug build. I am not good to advertise features! 😄
image

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 1, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3273f98
Status: ✅  Deploy successful!
Preview URL: https://af7eca51.tools-8rn.pages.dev
Branch Preview URL: https://feature-no-arguments.tools-8rn.pages.dev

View logs

@xunilrj xunilrj force-pushed the feature/no-arguments branch from fb58bf1 to 37bfa11 Compare July 1, 2022 16:20
@xunilrj xunilrj temporarily deployed to aws July 1, 2022 16:20 Inactive
@github-actions
Copy link

github-actions bot commented Jul 1, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 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 388 388 0
Failed 5558 5558 0
Panics 0 0 0
Coverage 6.53% 6.53% 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 12393 12393 0
Failed 3864 3864 0
Panics 0 0 0
Coverage 76.23% 76.23% 0.00%

@github-actions
Copy link

github-actions bot commented Jul 1, 2022

@xunilrj xunilrj temporarily deployed to aws July 1, 2022 16:29 Inactive
@xunilrj xunilrj temporarily deployed to aws July 1, 2022 17:16 Inactive
@xunilrj xunilrj temporarily deployed to aws July 1, 2022 17:20 Inactive
@xunilrj xunilrj temporarily deployed to aws July 1, 2022 17:26 Inactive
@xunilrj xunilrj temporarily deployed to aws July 1, 2022 18:05 Inactive
@xunilrj xunilrj changed the title Feature/no arguments feature(rome_js_analyzer): semantic rules and "no arguments" lint rule Jul 1, 2022
@ematipico
Copy link
Contributor

@xunilrj there's an empty file that is not supposed to be there. It's called services.rs

@@ -69,6 +75,9 @@ struct ErrorOutput(Vec<u8>);

impl io::Write for ErrorOutput {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// let str = std::str::from_utf8(buf).unwrap();
// let html = ansi_to_html::convert_escaped(str).unwrap();
// self.0.write(html.as_str().as_bytes())
self.0.write(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these comments still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Good catch.

@xunilrj xunilrj force-pushed the feature/no-arguments branch from 2808d35 to 0cd2de9 Compare July 5, 2022 09:07
@xunilrj xunilrj temporarily deployed to aws July 5, 2022 09:07 Inactive
@xunilrj xunilrj temporarily deployed to aws July 5, 2022 09:19 Inactive
@xunilrj xunilrj requested a review from ematipico July 5, 2022 11:46
@xunilrj xunilrj temporarily deployed to aws July 5, 2022 18:16 Inactive
@xunilrj xunilrj force-pushed the feature/no-arguments branch from a3a96a4 to 3273f98 Compare July 5, 2022 18:47
@xunilrj xunilrj temporarily deployed to aws July 5, 2022 18:47 Inactive
@xunilrj xunilrj merged commit 5bcf025 into main Jul 5, 2022
@xunilrj xunilrj deleted the feature/no-arguments branch July 5, 2022 19:14
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.

3 participants