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

feat(rome_js_analyze): useExponentiationOperator rule #3848

Merged
merged 12 commits into from
Dec 5, 2022

Conversation

kaioduarte
Copy link
Contributor

@kaioduarte kaioduarte commented Nov 24, 2022

Summary

Adds an initial implementation of this ESLint rule prefer-exponentiation-operator. There are some edge cases to be handled. For realistic usage, it looks fine.

Test Plan

cargo test -p rome_js_analyze -- use_exponentiation_operator

@netlify
Copy link

netlify bot commented Nov 24, 2022

Deploy Preview for docs-rometools ready!

Name Link
🔨 Latest commit 264e539
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/638dc541ee94340008dd74cc
😎 Deploy Preview https://deploy-preview-3848--docs-rometools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@kaioduarte kaioduarte changed the title feat(rome_js_analyze): useExponentiation rule feat(rome_js_analyze): useExponentiationOperator rule Nov 24, 2022
@ematipico
Copy link
Contributor

@kaioduarte considering that this is an initial implementation, would it be possible to create an issue where you can track works that need to be done for this rule?

@kaioduarte kaioduarte mentioned this pull request Nov 24, 2022
4 tasks
@kaioduarte
Copy link
Contributor Author

@ematipico here it is #3850

Comment on lines 69 to 132
let has_math = static_member_expr
.object()
.ok()?
.omit_parentheses()
.as_reference_identifier()?
.has_name("Math");
let has_pow = static_member_expr
.member()
.ok()?
.as_js_name()?
.value_token()
.ok()?
.token_text_trimmed()
== "pow";

if has_math && has_pow {
return Some(());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@xunilrj What's your take: Would it be faster to instead use the semantic model to get the global Math symbol and then find all references to it instead of running the rule on each static member expression?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. But we would need to be sure that the context has Math configured as global.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xunilrj do we have any rule that does that check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly. Let us leave the rule as it is, and make this change later as an optimization. Like we did for https://github.com/rome/tools/blob/main/crates/rome_js_analyze/src/semantic_analyzers/correctness/no_arguments.rs

@MichaReiser MichaReiser merged commit 58a8e38 into rome:main Dec 5, 2022
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.

5 participants