-
Notifications
You must be signed in to change notification settings - Fork 660
feat(rome_js_analyze): useExponentiationOperator
rule
#3848
Conversation
✅ Deploy Preview for docs-rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
useExponentiation
ruleuseExponentiationOperator
rule
@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? |
@ematipico here it is #3850 |
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(()); | ||
} |
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.
@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?
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.
Yes. But we would need to be sure that the context has Math configured as global.
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.
@xunilrj do we have any rule that does that check?
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.
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
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Outdated
Show resolved
Hide resolved
a6799dd
to
513189e
Compare
crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs
Show resolved
Hide resolved
aacc6da
to
87bca70
Compare
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