From 4ee906851ac832f1d991750b5ae8c0d08f5726c1 Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Sat, 2 Sep 2023 14:01:10 +0200 Subject: [PATCH] refactor(lint/useExponentiationOperator): avoid incorrect code fixes --- .../complexity/use_optional_chain.rs | 7 +- .../use_simplified_logic_expression.rs | 4 +- .../analyzers/nursery/use_arrow_function.rs | 9 +- .../style/use_exponentiation_operator.rs | 208 ++++------ .../suspicious/no_unsafe_negation.rs | 13 +- .../useExponentiationOperator/invalid.js | 8 - .../useExponentiationOperator/invalid.js.snap | 363 +++++------------- .../invalidAdjacentTokens.js.snap | 34 +- ...invalidBaseExpoentHigherPrecedence.js.snap | 18 +- .../invalidBaseExpoentLowerPrecedence.js.snap | 22 +- .../invalidClass.ts.snap | 8 +- ...invalidParentsWithHigherPrecedence.js.snap | 38 +- .../invalidParentsWithLowerPrecedence.js.snap | 24 +- .../invalidUnaryExpression.js.snap | 16 +- .../invalidWithComments.js | 7 + .../invalidWithComments.js.snap | 130 +++++++ .../invalidWithoutAutofix.js | 8 - .../invalidWithoutAutofix.js.snap | 106 ----- crates/rome_js_factory/src/make.rs | 14 +- crates/rome_js_syntax/src/expr_ext.rs | 19 +- .../rules/use-exponentiation-operator.md | 19 +- xtask/Cargo.toml | 4 +- xtask/bench/Cargo.toml | 46 +-- xtask/codegen/Cargo.toml | 66 ++-- xtask/contributors/Cargo.toml | 14 +- xtask/coverage/Cargo.toml | 48 +-- xtask/libs_bench/Cargo.toml | 30 +- xtask/lintdoc/Cargo.toml | 30 +- 28 files changed, 554 insertions(+), 759 deletions(-) create mode 100644 crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js create mode 100644 crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js.snap diff --git a/crates/rome_js_analyze/src/analyzers/complexity/use_optional_chain.rs b/crates/rome_js_analyze/src/analyzers/complexity/use_optional_chain.rs index 312da4c5cff6..137ac376dff4 100644 --- a/crates/rome_js_analyze/src/analyzers/complexity/use_optional_chain.rs +++ b/crates/rome_js_analyze/src/analyzers/complexity/use_optional_chain.rs @@ -205,12 +205,7 @@ impl Rule for UseOptionalChain { let need_parenthesis = left.precedence().ok()? < OperatorPrecedence::LeftHandSide; if need_parenthesis { - left = make::js_parenthesized_expression( - make::token(T!['(']), - left, - make::token(T![')']), - ) - .into(); + left = make::parenthesized(left).into(); } let next_member = match member.clone() { AnyJsMemberExpression::JsStaticMemberExpression(expression) => { diff --git a/crates/rome_js_analyze/src/analyzers/complexity/use_simplified_logic_expression.rs b/crates/rome_js_analyze/src/analyzers/complexity/use_simplified_logic_expression.rs index 6463fffcc114..0635844a7b9d 100644 --- a/crates/rome_js_analyze/src/analyzers/complexity/use_simplified_logic_expression.rs +++ b/crates/rome_js_analyze/src/analyzers/complexity/use_simplified_logic_expression.rs @@ -231,10 +231,8 @@ fn simplify_de_morgan(node: &JsLogicalExpression) -> Option { next_logic_expression = next_logic_expression.with_right(right.argument().ok()?); Some(make::js_unary_expression( make::token(T![!]), - AnyJsExpression::JsParenthesizedExpression(make::js_parenthesized_expression( - make::token(T!['(']), + AnyJsExpression::JsParenthesizedExpression(make::parenthesized( AnyJsExpression::JsLogicalExpression(next_logic_expression), - make::token(T![')']), )), )) } diff --git a/crates/rome_js_analyze/src/analyzers/nursery/use_arrow_function.rs b/crates/rome_js_analyze/src/analyzers/nursery/use_arrow_function.rs index ffe1bdace7ff..8a5d650c72d2 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/use_arrow_function.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/use_arrow_function.rs @@ -279,14 +279,7 @@ fn to_arrow_body(body: JsFunctionBody) -> AnyJsFunctionBody { }; if first_token.kind() == T!['{'] { // () => ({ ... }) - result = AnyJsFunctionBody::AnyJsExpression( - make::js_parenthesized_expression( - make::token(T!['(']), - return_arg, - make::token(T![')']), - ) - .into(), - ); + result = AnyJsFunctionBody::AnyJsExpression(make::parenthesized(return_arg).into()); } result } diff --git a/crates/rome_js_analyze/src/analyzers/style/use_exponentiation_operator.rs b/crates/rome_js_analyze/src/analyzers/style/use_exponentiation_operator.rs index c061a69043f7..83c567a3f75d 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_exponentiation_operator.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_exponentiation_operator.rs @@ -6,16 +6,19 @@ use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::{make, syntax::T}; use rome_js_syntax::{ - global_identifier, AnyJsExpression, AnyJsMemberExpression, JsBinaryOperator, JsCallExpression, - JsClassDeclaration, JsClassExpression, JsExtendsClause, JsInExpression, OperatorPrecedence, + global_identifier, AnyJsCallArgument, AnyJsExpression, AnyJsMemberExpression, JsBinaryOperator, + JsCallExpression, JsClassDeclaration, JsClassExpression, JsExtendsClause, JsInExpression, + OperatorPrecedence, +}; +use rome_rowan::{ + trim_leading_trivia_pieces, AstNode, AstSeparatedList, BatchMutationExt, SyntaxResult, }; -use rome_rowan::{AstNode, AstSeparatedList, BatchMutationExt}; declare_rule! { /// Disallow the use of `Math.pow` in favor of the `**` operator. /// - /// > Introduced in ES2016, the infix exponentiation operator ** is an alternative for the standard Math.pow function. - /// > Infix notation is considered to be more readable and thus more preferable than the function notation. + /// Introduced in ES2016, the infix exponentiation operator `**` is an alternative for the standard `Math.pow` function. + /// Infix notation is considered to be more readable and thus more preferable than the function notation. /// /// Source: https://eslint.org/docs/latest/rules/prefer-exponentiation-operator /// @@ -58,45 +61,6 @@ declare_rule! { } } -pub struct MathPowCall { - base: AnyJsExpression, - exponent: AnyJsExpression, -} - -impl MathPowCall { - fn make_base(&self) -> Option { - Some(if self.does_base_need_parens()? { - parenthesize_any_js_expression(&self.base) - } else { - self.base.clone() - }) - } - - fn make_exponent(&self) -> Option { - Some(if self.does_exponent_need_parens()? { - parenthesize_any_js_expression(&self.exponent) - } else { - self.exponent.clone() - }) - } - - /// Determines whether the base expression needs parens in an exponentiation binary expression. - fn does_base_need_parens(&self) -> Option { - Some( - // '**' is right-associative, parens are needed when Math.pow(a ** b, c) is converted to (a ** b) ** c - self.base.precedence().ok()? <= OperatorPrecedence::Exponential - // An unary operator cannot be used immediately before an exponentiation expression - || self.base.as_js_unary_expression().is_some() - || self.base.as_js_await_expression().is_some(), - ) - } - - /// Determines whether the exponent expression needs parens in an exponentiation binary expression. - fn does_exponent_need_parens(&self) -> Option { - Some(self.exponent.precedence().ok()? < OperatorPrecedence::Exponential) - } -} - impl Rule for UseExponentiationOperator { type Query = Semantic; type State = (); @@ -120,52 +84,63 @@ impl Rule for UseExponentiationOperator { } fn diagnostic(ctx: &RuleContext, _: &Self::State) -> Option { - let diagnostic = RuleDiagnostic::new( + Some(RuleDiagnostic::new( rule_category!(), ctx.query().range(), "Use the '**' operator instead of 'Math.pow'.", - ); - - Some(diagnostic) + )) } fn action(ctx: &RuleContext, _: &Self::State) -> Option { let node = ctx.query(); - - if !should_suggest_fix(node)? { + let args = node.arguments().ok()?; + let [Some(AnyJsCallArgument::AnyJsExpression(base)), Some(AnyJsCallArgument::AnyJsExpression(exponent)), None] = + node.get_arguments_by_index([0, 1, 2]) + else { return None; - } - - let mut mutation = ctx.root().begin(); - let [base, exponent] = node.get_arguments_by_index([0, 1]); - - let math_pow_call = MathPowCall { - base: base?.as_any_js_expression()?.clone().omit_parentheses(), - exponent: exponent?.as_any_js_expression()?.clone().omit_parentheses(), }; - - let new_node = make::js_binary_expression( - math_pow_call.make_base()?, - make::token(T![**]), - math_pow_call.make_exponent()?, - ); - - if let Some((needs_parens, parent)) = does_exponentiation_expression_need_parens(node) { + let base = if does_base_need_parens(&base).ok()? { + make::parenthesized(base).into() + } else { + base + }; + let exponent = if does_exponent_need_parens(&exponent).ok()? { + make::parenthesized(exponent).into() + } else { + exponent + }; + let comma_separator = args.args().separators().next()?.ok()?; + // Transfer comments before and after `base` and `exponent` + // which are associated with the comma or a paren. + let base = base + .prepend_trivia_pieces(args.l_paren_token().ok()?.trailing_trivia().pieces())? + .append_trivia_pieces(comma_separator.leading_trivia().pieces())?; + let exponent = exponent + .prepend_trivia_pieces(trim_leading_trivia_pieces( + comma_separator.trailing_trivia().pieces(), + ))? + .append_trivia_pieces(args.r_paren_token().ok()?.leading_trivia().pieces())?; + let mut mutation = ctx.root().begin(); + let new_node = AnyJsExpression::from(make::js_binary_expression( + base, + make::token_decorated_with_space(T![**]), + exponent, + )); + let new_node = if let Some((needs_parens, parent)) = + does_exponentiation_expression_need_parens(node) + { if needs_parens && parent.is_some() { - mutation.replace_node(parent.clone()?, parenthesize_any_js_expression(&parent?)); + mutation.replace_node(parent.clone()?, make::parenthesized(parent?).into()); } - - mutation.replace_node( - AnyJsExpression::from(node.clone()), - parenthesize_any_js_expression(&AnyJsExpression::from(new_node)), - ); + make::parenthesized(new_node).into() } else { - mutation.replace_node( - AnyJsExpression::from(node.clone()), - AnyJsExpression::from(new_node), - ); - } - + new_node + }; + // Transfer leading and trailing comments + let new_node = new_node + .prepend_trivia_pieces(node.syntax().first_leading_trivia()?.pieces())? + .append_trivia_pieces(node.syntax().last_trailing_trivia()?.pieces())?; + mutation.replace_node_discard_trivia(AnyJsExpression::from(node.clone()), new_node); Some(JsRuleAction { category: ActionCategory::QuickFix, applicability: Applicability::MaybeIncorrect, @@ -175,35 +150,6 @@ impl Rule for UseExponentiationOperator { } } -/// Verify if the autofix is safe to be applied and won't remove comments. -/// Argument list is considered valid if there's no spread arg and leading/trailing comments. -fn should_suggest_fix(node: &JsCallExpression) -> Option { - let arguments = node.arguments().ok()?; - let args_count = arguments.args().len(); - - Some( - args_count == 2 - && !arguments.l_paren_token().ok()?.has_leading_comments() - && !arguments.l_paren_token().ok()?.has_trailing_comments() - && !arguments.r_paren_token().ok()?.has_leading_comments() - && !arguments.r_paren_token().ok()?.has_trailing_comments() - && arguments.args().into_iter().flatten().all(|arg| { - !arg.syntax().has_leading_comments() - && !arg.syntax().has_trailing_comments() - && arg.as_js_spread().is_none() - }), - ) -} - -/// Wraps a [AnyJsExpression] in paretheses -fn parenthesize_any_js_expression(expr: &AnyJsExpression) -> AnyJsExpression { - AnyJsExpression::from(make::js_parenthesized_expression( - make::token(T!['(']), - expr.clone(), - make::token(T![')']), - )) -} - /// Determines whether the given parent node needs parens if used as the exponent in an exponentiation binary expression. fn does_exponentiation_expression_need_parens( node: &JsCallExpression, @@ -216,7 +162,6 @@ fn does_exponentiation_expression_need_parens( if extends_clause.parent::().is_some() { return Some((true, None)); } - if let Some(class_expr) = extends_clause.parent::() { let class_expr = AnyJsExpression::from(class_expr); if does_expression_need_parens(node, &class_expr)? { @@ -224,7 +169,6 @@ fn does_exponentiation_expression_need_parens( } } } - None } @@ -235,48 +179,37 @@ fn does_expression_need_parens( ) -> Option { let needs_parentheses = match &expression { // Skips already parenthesized expressions - AnyJsExpression::JsParenthesizedExpression(_) => return None, + AnyJsExpression::JsParenthesizedExpression(_) => return Some(false), AnyJsExpression::JsBinaryExpression(bin_expr) => { if bin_expr.parent::().is_some() { return Some(true); } - let binding = bin_expr.right().ok()?; let call_expr = binding.as_js_call_expression(); - bin_expr.operator().ok()? != JsBinaryOperator::Exponent || call_expr.is_none() || call_expr? != node } - AnyJsExpression::JsCallExpression(call_expr) => !call_expr + AnyJsExpression::JsCallExpression(call_expr) => call_expr .arguments() .ok()? .args() .iter() - .filter_map(|arg| { - let binding = arg.ok()?; - return binding - .as_any_js_expression()? - .as_js_call_expression() - .cloned(); + .find_map(|arg| { + Some(arg.ok()?.as_any_js_expression()?.as_js_call_expression()? == node) }) - .any(|arg| &arg == node), - AnyJsExpression::JsNewExpression(new_expr) => !new_expr + .is_none(), + AnyJsExpression::JsNewExpression(new_expr) => new_expr .arguments()? .args() .iter() - .filter_map(|arg| { - let binding = arg.ok()?; - return binding - .as_any_js_expression()? - .as_js_call_expression() - .cloned(); + .find_map(|arg| { + Some(arg.ok()?.as_any_js_expression()?.as_js_call_expression()? == node) }) - .any(|arg| &arg == node), + .is_none(), AnyJsExpression::JsComputedMemberExpression(member_expr) => { let binding = member_expr.member().ok()?; let call_expr = binding.as_js_call_expression(); - call_expr.is_none() || call_expr? != node } AnyJsExpression::JsInExpression(_) => return Some(true), @@ -286,6 +219,21 @@ fn does_expression_need_parens( | AnyJsExpression::JsTemplateExpression(_) => true, _ => false, }; - Some(needs_parentheses && expression.precedence().ok()? >= OperatorPrecedence::Exponential) } + +fn does_base_need_parens(base: &AnyJsExpression) -> SyntaxResult { + // '**' is right-associative, parens are needed when Math.pow(a ** b, c) is converted to (a ** b) ** c + Ok(base.precedence()? <= OperatorPrecedence::Exponential + // An unary operator cannot be used immediately before an exponentiation expression + || base.as_js_unary_expression().is_some() + || base.as_js_await_expression().is_some() + // Parenthesis could be avoided in the following cases. + // However, this improves readability. + || base.as_js_pre_update_expression().is_some() + || base.as_js_post_update_expression().is_some()) +} + +fn does_exponent_need_parens(exponent: &AnyJsExpression) -> SyntaxResult { + Ok(exponent.precedence()? < OperatorPrecedence::Exponential) +} diff --git a/crates/rome_js_analyze/src/analyzers/suspicious/no_unsafe_negation.rs b/crates/rome_js_analyze/src/analyzers/suspicious/no_unsafe_negation.rs index 446265b4c16e..7c309c839a8e 100644 --- a/crates/rome_js_analyze/src/analyzers/suspicious/no_unsafe_negation.rs +++ b/crates/rome_js_analyze/src/analyzers/suspicious/no_unsafe_negation.rs @@ -3,7 +3,7 @@ use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; -use rome_js_syntax::{AnyJsExpression, JsInExpression, JsInstanceofExpression, T}; +use rome_js_syntax::{AnyJsExpression, JsInExpression, JsInstanceofExpression}; use rome_rowan::{declare_node_union, AstNode, AstNodeExt, BatchMutationExt}; declare_rule! { @@ -100,10 +100,8 @@ impl Rule for NoUnsafeNegation { let next_expr = expr .clone() .replace_node_discard_trivia(left.clone(), argument)?; - let next_parenthesis_expression = make::js_parenthesized_expression( - make::token(T!['(']), + let next_parenthesis_expression = make::parenthesized( rome_js_syntax::AnyJsExpression::JsInstanceofExpression(next_expr), - make::token(T![')']), ); let next_unary_expression = make::js_unary_expression( unary_expression.operator_token().ok()?, @@ -122,11 +120,8 @@ impl Rule for NoUnsafeNegation { left.clone(), rome_js_syntax::AnyJsInProperty::AnyJsExpression(argument), )?; - let next_parenthesis_expression = make::js_parenthesized_expression( - make::token(T!['(']), - rome_js_syntax::AnyJsExpression::JsInExpression(next_expr), - make::token(T![')']), - ); + let next_parenthesis_expression = + make::parenthesized(rome_js_syntax::AnyJsExpression::JsInExpression(next_expr)); let next_unary_expression = make::js_unary_expression( unary_expression.operator_token().ok()?, AnyJsExpression::JsParenthesizedExpression(next_parenthesis_expression), diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js index 456fa7714caf..e47e9b9abdec 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js @@ -38,14 +38,6 @@ foo + (Math.pow(a, b)); (Math.pow(a, b)) + foo; `${(Math.pow(a, b))}`; -// doesn't preserve unnecessary parens around base and exponent -Math.pow((a), (b)) -Math.pow(((a)), ((b))) -Math.pow((a.foo), b) -Math.pow(a, (b.foo)) -Math.pow((a()), b) -Math.pow(a, (b())) - // Optional chaining Math.pow?.(a, b) Math?.pow(a, b) diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js.snap index ee5715474092..976a75024fff 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalid.js.snap @@ -44,14 +44,6 @@ foo + (Math.pow(a, b)); (Math.pow(a, b)) + foo; `${(Math.pow(a, b))}`; -// doesn't preserve unnecessary parens around base and exponent -Math.pow((a), (b)) -Math.pow(((a)), ((b))) -Math.pow((a.foo), b) -Math.pow(a, (b.foo)) -Math.pow((a()), b) -Math.pow(a, (b())) - // Optional chaining Math.pow?.(a, b) Math?.pow(a, b) @@ -81,7 +73,7 @@ invalid.js:1:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ i Suggested fix: Use the '**' operator instead of 'Math.pow'. 1 │ - Math.pow(a,·b); - 1 │ + a**b; + 1 │ + a·**·b; 2 2 │ (Math).pow(a, b); 3 3 │ @@ -103,7 +95,7 @@ invalid.js:2:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ 1 1 │ Math.pow(a, b); 2 │ - (Math).pow(a,·b); - 2 │ + a**b; + 2 │ + a·**·b; 3 3 │ 4 4 │ // able to catch some workarounds @@ -126,7 +118,7 @@ invalid.js:5:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ 3 3 │ 4 4 │ // able to catch some workarounds 5 │ - Math[`pow`](a,·b); - 5 │ + a**b; + 5 │ + a·**·b; 6 6 │ (Math)['pow'](a, b); 7 7 │ (Math)["pow"](a, b); @@ -150,7 +142,7 @@ invalid.js:6:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ 4 4 │ // able to catch some workarounds 5 5 │ Math[`pow`](a, b); 6 │ - (Math)['pow'](a,·b); - 6 │ + a**b; + 6 │ + a·**·b; 7 7 │ (Math)["pow"](a, b); 8 8 │ (Math)[`pow`](a, b); @@ -174,7 +166,7 @@ invalid.js:7:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ 5 5 │ Math[`pow`](a, b); 6 6 │ (Math)['pow'](a, b); 7 │ - (Math)["pow"](a,·b); - 7 │ + a**b; + 7 │ + a·**·b; 8 8 │ (Math)[`pow`](a, b); 9 9 │ @@ -198,7 +190,7 @@ invalid.js:8:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━ 6 6 │ (Math)['pow'](a, b); 7 7 │ (Math)["pow"](a, b); 8 │ - (Math)[`pow`](a,·b); - 8 │ + a**b; + 8 │ + a·**·b; 9 9 │ 10 10 │ // non-expression parents that don't require parens @@ -221,7 +213,7 @@ invalid.js:11:9 lint/style/useExponentiationOperator FIXABLE ━━━━━ 9 9 │ 10 10 │ // non-expression parents that don't require parens 11 │ - var·x·=·Math.pow(a,·b); - 11 │ + var·x·=·a**b; + 11 │ + var·x·=·a·**·b; 12 12 │ if(Math.pow(a, b)){} 13 13 │ for(;Math.pow(a, b);){} @@ -245,7 +237,7 @@ invalid.js:12:4 lint/style/useExponentiationOperator FIXABLE ━━━━━ 10 10 │ // non-expression parents that don't require parens 11 11 │ var x = Math.pow(a, b); 12 │ - if(Math.pow(a,·b)){} - 12 │ + if(a**b){} + 12 │ + if(a·**·b){} 13 13 │ for(;Math.pow(a, b);){} 14 14 │ switch(foo){ case Math.pow(a, b): break; } @@ -269,7 +261,7 @@ invalid.js:13:6 lint/style/useExponentiationOperator FIXABLE ━━━━━ 11 11 │ var x = Math.pow(a, b); 12 12 │ if(Math.pow(a, b)){} 13 │ - for(;Math.pow(a,·b);){} - 13 │ + for(;a**b;){} + 13 │ + for(;a·**·b;){} 14 14 │ switch(foo){ case Math.pow(a, b): break; } 15 15 │ { foo: Math.pow(a, b) } @@ -293,7 +285,7 @@ invalid.js:14:19 lint/style/useExponentiationOperator FIXABLE ━━━━━ 12 12 │ if(Math.pow(a, b)){} 13 13 │ for(;Math.pow(a, b);){} 14 │ - switch(foo){·case·Math.pow(a,·b):·break;·} - 14 │ + switch(foo){·case·a**b:·break;·} + 14 │ + switch(foo){·case·a·**·b:·break;·} 15 15 │ { foo: Math.pow(a, b) } 16 16 │ function foo(bar, baz = Math.pow(a, b), quux){} @@ -317,7 +309,7 @@ invalid.js:15:8 lint/style/useExponentiationOperator FIXABLE ━━━━━ 13 13 │ for(;Math.pow(a, b);){} 14 14 │ switch(foo){ case Math.pow(a, b): break; } 15 │ - {·foo:·Math.pow(a,·b)·} - 15 │ + {·foo:·a**b·} + 15 │ + {·foo:·a·**·b·} 16 16 │ function foo(bar, baz = Math.pow(a, b), quux){} 17 17 │ `${Math.pow(a, b)}` @@ -341,7 +333,7 @@ invalid.js:16:25 lint/style/useExponentiationOperator FIXABLE ━━━━━ 14 14 │ switch(foo){ case Math.pow(a, b): break; } 15 15 │ { foo: Math.pow(a, b) } 16 │ - function·foo(bar,·baz·=·Math.pow(a,·b),·quux){} - 16 │ + function·foo(bar,·baz·=·a**b,·quux){} + 16 │ + function·foo(bar,·baz·=·a·**·b,·quux){} 17 17 │ `${Math.pow(a, b)}` 18 18 │ @@ -365,7 +357,7 @@ invalid.js:17:4 lint/style/useExponentiationOperator FIXABLE ━━━━━ 15 15 │ { foo: Math.pow(a, b) } 16 16 │ function foo(bar, baz = Math.pow(a, b), quux){} 17 │ - `${Math.pow(a,·b)}` - 17 │ + `${a**b}` + 17 │ + `${a·**·b}` 18 18 │ 19 19 │ // non-expression parents that do require parens @@ -388,7 +380,7 @@ invalid.js:20:17 lint/style/useExponentiationOperator FIXABLE ━━━━━ 18 18 │ 19 19 │ // non-expression parents that do require parens 20 │ - class·C·extends·Math.pow(a,·b)·{} - 20 │ + class·C·extends·(a**b)·{} + 20 │ + class·C·extends·(a·**·b)·{} 21 21 │ 22 22 │ // already parenthesised, shouldn't insert extra parens @@ -411,7 +403,7 @@ invalid.js:23:3 lint/style/useExponentiationOperator FIXABLE ━━━━━ 21 21 │ 22 22 │ // already parenthesised, shouldn't insert extra parens 23 │ - +(Math.pow(a,·b)) - 23 │ + +(a**b) + 23 │ + +(a·**·b) 24 24 │ (Math.pow(a, b)).toString() 25 25 │ (class extends (Math.pow(a, b)) {}) @@ -435,7 +427,7 @@ invalid.js:24:2 lint/style/useExponentiationOperator FIXABLE ━━━━━ 22 22 │ // already parenthesised, shouldn't insert extra parens 23 23 │ +(Math.pow(a, b)) 24 │ - (Math.pow(a,·b)).toString() - 24 │ + (a**b).toString() + 24 │ + (a·**·b).toString() 25 25 │ (class extends (Math.pow(a, b)) {}) 26 26 │ class C extends (Math.pow(a, b)) {} @@ -459,7 +451,7 @@ invalid.js:25:17 lint/style/useExponentiationOperator FIXABLE ━━━━━ 23 23 │ +(Math.pow(a, b)) 24 24 │ (Math.pow(a, b)).toString() 25 │ - (class·extends·(Math.pow(a,·b))·{}) - 25 │ + (class·extends·(a**b)·{}) + 25 │ + (class·extends·(a·**·b)·{}) 26 26 │ class C extends (Math.pow(a, b)) {} 27 27 │ @@ -483,7 +475,7 @@ invalid.js:26:18 lint/style/useExponentiationOperator FIXABLE ━━━━━ 24 24 │ (Math.pow(a, b)).toString() 25 25 │ (class extends (Math.pow(a, b)) {}) 26 │ - class·C·extends·(Math.pow(a,·b))·{} - 26 │ + class·C·extends·(a**b)·{} + 26 │ + class·C·extends·(a·**·b)·{} 27 27 │ 28 28 │ // '**' is right-associative, that applies to both parent and child nodes @@ -506,7 +498,7 @@ invalid.js:29:6 lint/style/useExponentiationOperator FIXABLE ━━━━━ 27 27 │ 28 28 │ // '**' is right-associative, that applies to both parent and child nodes 29 │ - a·**·Math.pow(b,·c); - 29 │ + a·**·b**c; + 29 │ + a·**·b·**·c; 30 30 │ Math.pow(a, b) ** c; 31 31 │ Math.pow(a, b ** c); @@ -530,7 +522,7 @@ invalid.js:30:1 lint/style/useExponentiationOperator FIXABLE ━━━━━ 28 28 │ // '**' is right-associative, that applies to both parent and child nodes 29 29 │ a ** Math.pow(b, c); 30 │ - Math.pow(a,·b)·**·c; - 30 │ + (a**b)·**·c; + 30 │ + (a·**·b)·**·c; 31 31 │ Math.pow(a, b ** c); 32 32 │ Math.pow(a ** b, c); @@ -554,7 +546,7 @@ invalid.js:31:1 lint/style/useExponentiationOperator FIXABLE ━━━━━ 29 29 │ a ** Math.pow(b, c); 30 30 │ Math.pow(a, b) ** c; 31 │ - Math.pow(a,·b·**·c); - 31 │ + a**b·**·c; + 31 │ + a·**·b·**·c; 32 32 │ Math.pow(a ** b, c); 33 33 │ a ** Math.pow(b ** c, d ** e) ** f; @@ -578,7 +570,7 @@ invalid.js:32:1 lint/style/useExponentiationOperator FIXABLE ━━━━━ 30 30 │ Math.pow(a, b) ** c; 31 31 │ Math.pow(a, b ** c); 32 │ - Math.pow(a·**·b,·c); - 32 │ + (a·**·b)**c; + 32 │ + (a·**·b)·**·c; 33 33 │ a ** Math.pow(b ** c, d ** e) ** f; 34 34 │ @@ -602,7 +594,7 @@ invalid.js:33:6 lint/style/useExponentiationOperator FIXABLE ━━━━━ 31 31 │ Math.pow(a, b ** c); 32 32 │ Math.pow(a ** b, c); 33 │ - a·**·Math.pow(b·**·c,·d·**·e)·**·f; - 33 │ + a·**·((b·**·c)**d·**·e)·**·f; + 33 │ + a·**·((b·**·c)·**·d·**·e)·**·f; 34 34 │ 35 35 │ // doesn't remove already existing unnecessary parens around the whole expression @@ -625,7 +617,7 @@ invalid.js:36:2 lint/style/useExponentiationOperator FIXABLE ━━━━━ 34 34 │ 35 35 │ // doesn't remove already existing unnecessary parens around the whole expression 36 │ - (Math.pow(a,·b)); - 36 │ + (a**b); + 36 │ + (a·**·b); 37 37 │ foo + (Math.pow(a, b)); 38 38 │ (Math.pow(a, b)) + foo; @@ -649,7 +641,7 @@ invalid.js:37:8 lint/style/useExponentiationOperator FIXABLE ━━━━━ 35 35 │ // doesn't remove already existing unnecessary parens around the whole expression 36 36 │ (Math.pow(a, b)); 37 │ - foo·+·(Math.pow(a,·b)); - 37 │ + foo·+·(a**b); + 37 │ + foo·+·(a·**·b); 38 38 │ (Math.pow(a, b)) + foo; 39 39 │ `${(Math.pow(a, b))}`; @@ -673,7 +665,7 @@ invalid.js:38:2 lint/style/useExponentiationOperator FIXABLE ━━━━━ 36 36 │ (Math.pow(a, b)); 37 37 │ foo + (Math.pow(a, b)); 38 │ - (Math.pow(a,·b))·+·foo; - 38 │ + (a**b)·+·foo; + 38 │ + (a·**·b)·+·foo; 39 39 │ `${(Math.pow(a, b))}`; 40 40 │ @@ -690,16 +682,16 @@ invalid.js:39:5 lint/style/useExponentiationOperator FIXABLE ━━━━━ > 39 │ `${(Math.pow(a, b))}`; │ ^^^^^^^^^^^^^^ 40 │ - 41 │ // doesn't preserve unnecessary parens around base and exponent + 41 │ // Optional chaining i Suggested fix: Use the '**' operator instead of 'Math.pow'. 37 37 │ foo + (Math.pow(a, b)); 38 38 │ (Math.pow(a, b)) + foo; 39 │ - `${(Math.pow(a,·b))}`; - 39 │ + `${(a**b)}`; + 39 │ + `${(a·**·b)}`; 40 40 │ - 41 41 │ // doesn't preserve unnecessary parens around base and exponent + 41 41 │ // Optional chaining ``` @@ -709,20 +701,20 @@ invalid.js:42:1 lint/style/useExponentiationOperator FIXABLE ━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 41 │ // doesn't preserve unnecessary parens around base and exponent - > 42 │ Math.pow((a), (b)) - │ ^^^^^^^^^^^^^^^^^^ - 43 │ Math.pow(((a)), ((b))) - 44 │ Math.pow((a.foo), b) + 41 │ // Optional chaining + > 42 │ Math.pow?.(a, b) + │ ^^^^^^^^^^^^^^^^ + 43 │ Math?.pow(a, b) + 44 │ Math?.pow?.(a, b) i Suggested fix: Use the '**' operator instead of 'Math.pow'. 40 40 │ - 41 41 │ // doesn't preserve unnecessary parens around base and exponent - 42 │ - Math.pow((a),·(b)) - 42 │ + a**b - 43 43 │ Math.pow(((a)), ((b))) - 44 44 │ Math.pow((a.foo), b) + 41 41 │ // Optional chaining + 42 │ - Math.pow?.(a,·b) + 42 │ + a·**·b + 43 43 │ Math?.pow(a, b) + 44 44 │ Math?.pow?.(a, b) ``` @@ -732,280 +724,137 @@ invalid.js:43:1 lint/style/useExponentiationOperator FIXABLE ━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 41 │ // doesn't preserve unnecessary parens around base and exponent - 42 │ Math.pow((a), (b)) - > 43 │ Math.pow(((a)), ((b))) - │ ^^^^^^^^^^^^^^^^^^^^^^ - 44 │ Math.pow((a.foo), b) - 45 │ Math.pow(a, (b.foo)) - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 41 41 │ // doesn't preserve unnecessary parens around base and exponent - 42 42 │ Math.pow((a), (b)) - 43 │ - Math.pow(((a)),·((b))) - 43 │ + a**b - 44 44 │ Math.pow((a.foo), b) - 45 45 │ Math.pow(a, (b.foo)) - - -``` - -``` -invalid.js:44:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 42 │ Math.pow((a), (b)) - 43 │ Math.pow(((a)), ((b))) - > 44 │ Math.pow((a.foo), b) - │ ^^^^^^^^^^^^^^^^^^^^ - 45 │ Math.pow(a, (b.foo)) - 46 │ Math.pow((a()), b) - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 42 42 │ Math.pow((a), (b)) - 43 43 │ Math.pow(((a)), ((b))) - 44 │ - Math.pow((a.foo),·b) - 44 │ + a.foo**b - 45 45 │ Math.pow(a, (b.foo)) - 46 46 │ Math.pow((a()), b) - - -``` - -``` -invalid.js:45:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 43 │ Math.pow(((a)), ((b))) - 44 │ Math.pow((a.foo), b) - > 45 │ Math.pow(a, (b.foo)) - │ ^^^^^^^^^^^^^^^^^^^^ - 46 │ Math.pow((a()), b) - 47 │ Math.pow(a, (b())) - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 43 43 │ Math.pow(((a)), ((b))) - 44 44 │ Math.pow((a.foo), b) - 45 │ - Math.pow(a,·(b.foo)) - 45 │ + a**b.foo - 46 46 │ Math.pow((a()), b) - 47 47 │ Math.pow(a, (b())) - - -``` - -``` -invalid.js:46:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 44 │ Math.pow((a.foo), b) - 45 │ Math.pow(a, (b.foo)) - > 46 │ Math.pow((a()), b) - │ ^^^^^^^^^^^^^^^^^^ - 47 │ Math.pow(a, (b())) - 48 │ - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 44 44 │ Math.pow((a.foo), b) - 45 45 │ Math.pow(a, (b.foo)) - 46 │ - Math.pow((a()),·b) - 46 │ + a()**b - 47 47 │ Math.pow(a, (b())) - 48 48 │ - - -``` - -``` -invalid.js:47:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 45 │ Math.pow(a, (b.foo)) - 46 │ Math.pow((a()), b) - > 47 │ Math.pow(a, (b())) - │ ^^^^^^^^^^^^^^^^^^ - 48 │ - 49 │ // Optional chaining - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 45 45 │ Math.pow(a, (b.foo)) - 46 46 │ Math.pow((a()), b) - 47 │ - Math.pow(a,·(b())) - 47 │ + a**b() - 48 48 │ - 49 49 │ // Optional chaining - - -``` - -``` -invalid.js:50:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 49 │ // Optional chaining - > 50 │ Math.pow?.(a, b) - │ ^^^^^^^^^^^^^^^^ - 51 │ Math?.pow(a, b) - 52 │ Math?.pow?.(a, b) - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 48 48 │ - 49 49 │ // Optional chaining - 50 │ - Math.pow?.(a,·b) - 50 │ + a**b - 51 51 │ Math?.pow(a, b) - 52 52 │ Math?.pow?.(a, b) - - -``` - -``` -invalid.js:51:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 49 │ // Optional chaining - 50 │ Math.pow?.(a, b) - > 51 │ Math?.pow(a, b) + 41 │ // Optional chaining + 42 │ Math.pow?.(a, b) + > 43 │ Math?.pow(a, b) │ ^^^^^^^^^^^^^^^ - 52 │ Math?.pow?.(a, b) - 53 │ ;(Math?.pow)(a, b) + 44 │ Math?.pow?.(a, b) + 45 │ ;(Math?.pow)(a, b) i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 49 49 │ // Optional chaining - 50 50 │ Math.pow?.(a, b) - 51 │ - Math?.pow(a,·b) - 51 │ + a**b - 52 52 │ Math?.pow?.(a, b) - 53 53 │ ;(Math?.pow)(a, b) + 41 41 │ // Optional chaining + 42 42 │ Math.pow?.(a, b) + 43 │ - Math?.pow(a,·b) + 43 │ + a·**·b + 44 44 │ Math?.pow?.(a, b) + 45 45 │ ;(Math?.pow)(a, b) ``` ``` -invalid.js:52:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:44:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 50 │ Math.pow?.(a, b) - 51 │ Math?.pow(a, b) - > 52 │ Math?.pow?.(a, b) + 42 │ Math.pow?.(a, b) + 43 │ Math?.pow(a, b) + > 44 │ Math?.pow?.(a, b) │ ^^^^^^^^^^^^^^^^^ - 53 │ ;(Math?.pow)(a, b) - 54 │ ;(Math?.pow)?.(a, b) + 45 │ ;(Math?.pow)(a, b) + 46 │ ;(Math?.pow)?.(a, b) i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 50 50 │ Math.pow?.(a, b) - 51 51 │ Math?.pow(a, b) - 52 │ - Math?.pow?.(a,·b) - 52 │ + a**b - 53 53 │ ;(Math?.pow)(a, b) - 54 54 │ ;(Math?.pow)?.(a, b) + 42 42 │ Math.pow?.(a, b) + 43 43 │ Math?.pow(a, b) + 44 │ - Math?.pow?.(a,·b) + 44 │ + a·**·b + 45 45 │ ;(Math?.pow)(a, b) + 46 46 │ ;(Math?.pow)?.(a, b) ``` ``` -invalid.js:53:2 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:45:2 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 51 │ Math?.pow(a, b) - 52 │ Math?.pow?.(a, b) - > 53 │ ;(Math?.pow)(a, b) + 43 │ Math?.pow(a, b) + 44 │ Math?.pow?.(a, b) + > 45 │ ;(Math?.pow)(a, b) │ ^^^^^^^^^^^^^^^^^ - 54 │ ;(Math?.pow)?.(a, b) - 55 │ + 46 │ ;(Math?.pow)?.(a, b) + 47 │ i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 51 51 │ Math?.pow(a, b) - 52 52 │ Math?.pow?.(a, b) - 53 │ - ;(Math?.pow)(a,·b) - 53 │ + ;a**b - 54 54 │ ;(Math?.pow)?.(a, b) - 55 55 │ + 43 43 │ Math?.pow(a, b) + 44 44 │ Math?.pow?.(a, b) + 45 │ - ;(Math?.pow)(a,·b) + 45 │ + ;a·**·b + 46 46 │ ;(Math?.pow)?.(a, b) + 47 47 │ ``` ``` -invalid.js:54:2 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:46:2 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 52 │ Math?.pow?.(a, b) - 53 │ ;(Math?.pow)(a, b) - > 54 │ ;(Math?.pow)?.(a, b) + 44 │ Math?.pow?.(a, b) + 45 │ ;(Math?.pow)(a, b) + > 46 │ ;(Math?.pow)?.(a, b) │ ^^^^^^^^^^^^^^^^^^^ - 55 │ - 56 │ // doesn't put extra parens + 47 │ + 48 │ // doesn't put extra parens i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 52 52 │ Math?.pow?.(a, b) - 53 53 │ ;(Math?.pow)(a, b) - 54 │ - ;(Math?.pow)?.(a,·b) - 54 │ + ;a**b - 55 55 │ - 56 56 │ // doesn't put extra parens + 44 44 │ Math?.pow?.(a, b) + 45 45 │ ;(Math?.pow)(a, b) + 46 │ - ;(Math?.pow)?.(a,·b) + 46 │ + ;a·**·b + 47 47 │ + 48 48 │ // doesn't put extra parens ``` ``` -invalid.js:57:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:49:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 56 │ // doesn't put extra parens - > 57 │ Math.pow((a + b), (c + d)) + 48 │ // doesn't put extra parens + > 49 │ Math.pow((a + b), (c + d)) │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ - 58 │ - 59 │ // tokens that can be adjacent + 50 │ + 51 │ // tokens that can be adjacent i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 55 55 │ - 56 56 │ // doesn't put extra parens - 57 │ - Math.pow((a·+·b),·(c·+·d)) - 57 │ + (a·+·b)**(c·+·d) - 58 58 │ - 59 59 │ // tokens that can be adjacent + 47 47 │ + 48 48 │ // doesn't put extra parens + 49 │ - Math.pow((a·+·b),·(c·+·d)) + 49 │ + (a·+·b)·**·(c·+·d) + 50 50 │ + 51 51 │ // tokens that can be adjacent ``` ``` -invalid.js:60:3 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:52:3 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Use the '**' operator instead of 'Math.pow'. - 59 │ // tokens that can be adjacent - > 60 │ a+Math.pow(b, c)+d + 51 │ // tokens that can be adjacent + > 52 │ a+Math.pow(b, c)+d │ ^^^^^^^^^^^^^^ - 61 │ + 53 │ i Suggested fix: Use the '**' operator instead of 'Math.pow'. - 58 58 │ - 59 59 │ // tokens that can be adjacent - 60 │ - a+Math.pow(b,·c)+d - 60 │ + a+b**c+d - 61 61 │ + 50 50 │ + 51 51 │ // tokens that can be adjacent + 52 │ - a+Math.pow(b,·c)+d + 52 │ + a+b·**·c+d + 53 53 │ ``` diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidAdjacentTokens.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidAdjacentTokens.js.snap index 1384e3876049..d25da2631c84 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidAdjacentTokens.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidAdjacentTokens.js.snap @@ -42,7 +42,7 @@ invalidAdjacentTokens.js:2:3 lint/style/useExponentiationOperator FIXABLE ━ 1 1 │ // tokens that cannot be adjacent 2 │ - a+Math.pow(++b,·c); - 2 │ + a+++b**c; + 2 │ + a+(++b)·**·c; 3 3 │ (a)+(Math).pow((++b), c); 4 4 │ Math.pow(a, b)in c @@ -66,7 +66,7 @@ invalidAdjacentTokens.js:3:5 lint/style/useExponentiationOperator FIXABLE ━ 1 1 │ // tokens that cannot be adjacent 2 2 │ a+Math.pow(++b, c); 3 │ - (a)+(Math).pow((++b),·c); - 3 │ + (a)+++b**c; + 3 │ + (a)+(++b)·**·c; 4 4 │ Math.pow(a, b)in c 5 5 │ Math.pow(a, (b))in (c) @@ -90,7 +90,7 @@ invalidAdjacentTokens.js:4:1 lint/style/useExponentiationOperator FIXABLE ━ 2 2 │ a+Math.pow(++b, c); 3 3 │ (a)+(Math).pow((++b), c); 4 │ - Math.pow(a,·b)in·c - 4 │ + (a**b)in·c + 4 │ + (a·**·b)in·c 5 5 │ Math.pow(a, (b))in (c) 6 6 │ a+Math.pow(++b, c)in d @@ -114,7 +114,7 @@ invalidAdjacentTokens.js:5:1 lint/style/useExponentiationOperator FIXABLE ━ 3 3 │ (a)+(Math).pow((++b), c); 4 4 │ Math.pow(a, b)in c 5 │ - Math.pow(a,·(b))in·(c) - 5 │ + (a**b)in·(c) + 5 │ + (a·**·(b))in·(c) 6 6 │ a+Math.pow(++b, c)in d 7 7 │ a+Math.pow( ++b, c )in d @@ -138,7 +138,7 @@ invalidAdjacentTokens.js:6:3 lint/style/useExponentiationOperator FIXABLE ━ 4 4 │ Math.pow(a, b)in c 5 5 │ Math.pow(a, (b))in (c) 6 │ - a+Math.pow(++b,·c)in·d - 6 │ + a+(++b**c)in·d + 6 │ + a+((++b)·**·c)in·d 7 7 │ a+Math.pow( ++b, c )in d 8 8 │ @@ -162,7 +162,7 @@ invalidAdjacentTokens.js:7:3 lint/style/useExponentiationOperator FIXABLE ━ 5 5 │ Math.pow(a, (b))in (c) 6 6 │ a+Math.pow(++b, c)in d 7 │ - a+Math.pow(·++b,·c·)in·d - 7 │ + a+(++b**c·)in·d + 7 │ + a+(·(++b)·**·c·)in·d 8 8 │ 9 9 │ // tokens that cannot be adjacent, but there is already space or something else between @@ -185,7 +185,7 @@ invalidAdjacentTokens.js:10:4 lint/style/useExponentiationOperator FIXABLE ━ 8 8 │ 9 9 │ // tokens that cannot be adjacent, but there is already space or something else between 10 │ - a+·Math.pow(++b,·c)·in·d - 10 │ + a+·(++b**c)·in·d + 10 │ + a+·((++b)·**·c)·in·d 11 11 │ // a+/**/Math.pow(++b, c)/**/in d // ignored because of comments 12 12 │ a+(Math.pow(++b, c))in d @@ -209,7 +209,7 @@ invalidAdjacentTokens.js:12:4 lint/style/useExponentiationOperator FIXABLE ━ 10 10 │ a+ Math.pow(++b, c) in d 11 11 │ // a+/**/Math.pow(++b, c)/**/in d // ignored because of comments 12 │ - a+(Math.pow(++b,·c))in·d - 12 │ + a+(++b**c)in·d + 12 │ + a+((++b)·**·c)in·d 13 13 │ 14 14 │ // tokens that cannot be adjacent, but the autofix inserts parens required for precedence @@ -232,7 +232,7 @@ invalidAdjacentTokens.js:15:2 lint/style/useExponentiationOperator FIXABLE ━ 13 13 │ 14 14 │ // tokens that cannot be adjacent, but the autofix inserts parens required for precedence 15 │ - +Math.pow(++a,·b) - 15 │ + +(++a**b) + 15 │ + +((++a)·**·b) 16 16 │ Math.pow(a, b + c)in d 17 17 │ Math.pow(a, b) + Math.pow(c, d) @@ -256,7 +256,7 @@ invalidAdjacentTokens.js:16:1 lint/style/useExponentiationOperator FIXABLE ━ 14 14 │ // tokens that cannot be adjacent, but the autofix inserts parens required for precedence 15 15 │ +Math.pow(++a, b) 16 │ - Math.pow(a,·b·+·c)in·d - 16 │ + (a**(b·+·c))in·d + 16 │ + (a·**·(b·+·c))in·d 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 18 │ Math.pow(Math.pow(a, b), Math.pow(c, d)) @@ -280,7 +280,7 @@ invalidAdjacentTokens.js:17:1 lint/style/useExponentiationOperator FIXABLE ━ 15 15 │ +Math.pow(++a, b) 16 16 │ Math.pow(a, b + c)in d 17 │ - Math.pow(a,·b)·+·Math.pow(c,·d) - 17 │ + a**b·+·Math.pow(c,·d) + 17 │ + a·**·b·+·Math.pow(c,·d) 18 18 │ Math.pow(Math.pow(a, b), Math.pow(c, d)) 19 19 │ Math.pow(a, b)**Math.pow(c, d) @@ -304,7 +304,7 @@ invalidAdjacentTokens.js:17:18 lint/style/useExponentiationOperator FIXABLE 15 15 │ +Math.pow(++a, b) 16 16 │ Math.pow(a, b + c)in d 17 │ - Math.pow(a,·b)·+·Math.pow(c,·d) - 17 │ + Math.pow(a,·b)·+·c**d + 17 │ + Math.pow(a,·b)·+·c·**·d 18 18 │ Math.pow(Math.pow(a, b), Math.pow(c, d)) 19 19 │ Math.pow(a, b)**Math.pow(c, d) @@ -328,7 +328,7 @@ invalidAdjacentTokens.js:18:1 lint/style/useExponentiationOperator FIXABLE ━ 16 16 │ Math.pow(a, b + c)in d 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 │ - Math.pow(Math.pow(a,·b),·Math.pow(c,·d)) - 18 │ + Math.pow(a,·b)**Math.pow(c,·d) + 18 │ + Math.pow(a,·b)·**·Math.pow(c,·d) 19 19 │ Math.pow(a, b)**Math.pow(c, d) 20 20 │ @@ -352,7 +352,7 @@ invalidAdjacentTokens.js:18:10 lint/style/useExponentiationOperator FIXABLE 16 16 │ Math.pow(a, b + c)in d 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 │ - Math.pow(Math.pow(a,·b),·Math.pow(c,·d)) - 18 │ + Math.pow(a**b,·Math.pow(c,·d)) + 18 │ + Math.pow(a·**·b,·Math.pow(c,·d)) 19 19 │ Math.pow(a, b)**Math.pow(c, d) 20 20 │ @@ -376,7 +376,7 @@ invalidAdjacentTokens.js:18:26 lint/style/useExponentiationOperator FIXABLE 16 16 │ Math.pow(a, b + c)in d 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 │ - Math.pow(Math.pow(a,·b),·Math.pow(c,·d)) - 18 │ + Math.pow(Math.pow(a,·b),·c**d) + 18 │ + Math.pow(Math.pow(a,·b),·c·**·d) 19 19 │ Math.pow(a, b)**Math.pow(c, d) 20 20 │ @@ -399,7 +399,7 @@ invalidAdjacentTokens.js:19:1 lint/style/useExponentiationOperator FIXABLE ━ 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 18 │ Math.pow(Math.pow(a, b), Math.pow(c, d)) 19 │ - Math.pow(a,·b)**Math.pow(c,·d) - 19 │ + (a**b)**Math.pow(c,·d) + 19 │ + (a·**·b)**Math.pow(c,·d) 20 20 │ @@ -421,7 +421,7 @@ invalidAdjacentTokens.js:19:17 lint/style/useExponentiationOperator FIXABLE 17 17 │ Math.pow(a, b) + Math.pow(c, d) 18 18 │ Math.pow(Math.pow(a, b), Math.pow(c, d)) 19 │ - Math.pow(a,·b)**Math.pow(c,·d) - 19 │ + Math.pow(a,·b)**c**d + 19 │ + Math.pow(a,·b)**c·**·d 20 20 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentHigherPrecedence.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentHigherPrecedence.js.snap index 0d075f4dba59..87730c06ef44 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentHigherPrecedence.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentHigherPrecedence.js.snap @@ -33,7 +33,7 @@ invalidBaseExpoentHigherPrecedence.js:2:2 lint/style/useExponentiationOperator 1 1 │ // base and exponent with a higher precedence 2 │ - ·Math.pow(2,·3) - 2 │ + ·2**3 + 2 │ + ·2·**·3 3 3 │ Math.pow(a.foo, b) 4 4 │ Math.pow(a, b.foo) @@ -57,7 +57,7 @@ invalidBaseExpoentHigherPrecedence.js:3:2 lint/style/useExponentiationOperator 1 1 │ // base and exponent with a higher precedence 2 2 │ Math.pow(2, 3) 3 │ - ·Math.pow(a.foo,·b) - 3 │ + ·a.foo**b + 3 │ + ·a.foo·**·b 4 4 │ Math.pow(a, b.foo) 5 5 │ Math.pow(a(), b) @@ -81,7 +81,7 @@ invalidBaseExpoentHigherPrecedence.js:4:2 lint/style/useExponentiationOperator 2 2 │ Math.pow(2, 3) 3 3 │ Math.pow(a.foo, b) 4 │ - ·Math.pow(a,·b.foo) - 4 │ + ·a**b.foo + 4 │ + ·a·**·b.foo 5 5 │ Math.pow(a(), b) 6 6 │ Math.pow(a, b()) @@ -105,7 +105,7 @@ invalidBaseExpoentHigherPrecedence.js:5:2 lint/style/useExponentiationOperator 3 3 │ Math.pow(a.foo, b) 4 4 │ Math.pow(a, b.foo) 5 │ - ·Math.pow(a(),·b) - 5 │ + ·a()**b + 5 │ + ·a()·**·b 6 6 │ Math.pow(a, b()) 7 7 │ Math.pow(++a, ++b) @@ -129,7 +129,7 @@ invalidBaseExpoentHigherPrecedence.js:6:2 lint/style/useExponentiationOperator 4 4 │ Math.pow(a, b.foo) 5 5 │ Math.pow(a(), b) 6 │ - ·Math.pow(a,·b()) - 6 │ + ·a**b() + 6 │ + ·a·**·b() 7 7 │ Math.pow(++a, ++b) 8 8 │ Math.pow(a++, ++b) @@ -153,7 +153,7 @@ invalidBaseExpoentHigherPrecedence.js:7:2 lint/style/useExponentiationOperator 5 5 │ Math.pow(a(), b) 6 6 │ Math.pow(a, b()) 7 │ - ·Math.pow(++a,·++b) - 7 │ + ·++a**++b + 7 │ + ·(++a)·**·++b 8 8 │ Math.pow(a++, ++b) 9 9 │ Math.pow(a--, b--) @@ -177,7 +177,7 @@ invalidBaseExpoentHigherPrecedence.js:8:2 lint/style/useExponentiationOperator 6 6 │ Math.pow(a, b()) 7 7 │ Math.pow(++a, ++b) 8 │ - ·Math.pow(a++,·++b) - 8 │ + ·a++**++b + 8 │ + ·(a++)·**·++b 9 9 │ Math.pow(a--, b--) 10 10 │ Math.pow(--a, b--) @@ -201,7 +201,7 @@ invalidBaseExpoentHigherPrecedence.js:9:2 lint/style/useExponentiationOperator 7 7 │ Math.pow(++a, ++b) 8 8 │ Math.pow(a++, ++b) 9 │ - ·Math.pow(a--,·b--) - 9 │ + ·a--**b-- + 9 │ + ·(a--)·**·b-- 10 10 │ Math.pow(--a, b--) 11 11 │ @@ -224,7 +224,7 @@ invalidBaseExpoentHigherPrecedence.js:10:2 lint/style/useExponentiationOperator 8 8 │ Math.pow(a++, ++b) 9 9 │ Math.pow(a--, b--) 10 │ - ·Math.pow(--a,·b--) - 10 │ + ·--a**b-- + 10 │ + ·(--a)·**·b-- 11 11 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentLowerPrecedence.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentLowerPrecedence.js.snap index 0abb7deddb84..ec87d3cc2482 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentLowerPrecedence.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidBaseExpoentLowerPrecedence.js.snap @@ -35,7 +35,7 @@ invalidBaseExpoentLowerPrecedence.js:2:1 lint/style/useExponentiationOperator F 1 1 │ // base and exponent with a lower precedence 2 │ - Math.pow(a·*·b,·c) - 2 │ + (a·*·b)**c + 2 │ + (a·*·b)·**·c 3 3 │ Math.pow(a, b * c) 4 4 │ Math.pow(a / b, c) @@ -59,7 +59,7 @@ invalidBaseExpoentLowerPrecedence.js:3:1 lint/style/useExponentiationOperator F 1 1 │ // base and exponent with a lower precedence 2 2 │ Math.pow(a * b, c) 3 │ - Math.pow(a,·b·*·c) - 3 │ + a**(b·*·c) + 3 │ + a·**·(b·*·c) 4 4 │ Math.pow(a / b, c) 5 5 │ Math.pow(a, b / c) @@ -83,7 +83,7 @@ invalidBaseExpoentLowerPrecedence.js:4:1 lint/style/useExponentiationOperator F 2 2 │ Math.pow(a * b, c) 3 3 │ Math.pow(a, b * c) 4 │ - Math.pow(a·/·b,·c) - 4 │ + (a·/·b)**c + 4 │ + (a·/·b)·**·c 5 5 │ Math.pow(a, b / c) 6 6 │ Math.pow(a + b, 3) @@ -107,7 +107,7 @@ invalidBaseExpoentLowerPrecedence.js:5:1 lint/style/useExponentiationOperator F 3 3 │ Math.pow(a, b * c) 4 4 │ Math.pow(a / b, c) 5 │ - Math.pow(a,·b·/·c) - 5 │ + a**(b·/·c) + 5 │ + a·**·(b·/·c) 6 6 │ Math.pow(a + b, 3) 7 7 │ Math.pow(2, a - b) @@ -131,7 +131,7 @@ invalidBaseExpoentLowerPrecedence.js:6:1 lint/style/useExponentiationOperator F 4 4 │ Math.pow(a / b, c) 5 5 │ Math.pow(a, b / c) 6 │ - Math.pow(a·+·b,·3) - 6 │ + (a·+·b)**3 + 6 │ + (a·+·b)·**·3 7 7 │ Math.pow(2, a - b) 8 8 │ Math.pow(a + b, c + d) @@ -155,7 +155,7 @@ invalidBaseExpoentLowerPrecedence.js:7:1 lint/style/useExponentiationOperator F 5 5 │ Math.pow(a, b / c) 6 6 │ Math.pow(a + b, 3) 7 │ - Math.pow(2,·a·-·b) - 7 │ + 2**(a·-·b) + 7 │ + 2·**·(a·-·b) 8 8 │ Math.pow(a + b, c + d) 9 9 │ Math.pow(a = b, c = d) @@ -179,7 +179,7 @@ invalidBaseExpoentLowerPrecedence.js:8:1 lint/style/useExponentiationOperator F 6 6 │ Math.pow(a + b, 3) 7 7 │ Math.pow(2, a - b) 8 │ - Math.pow(a·+·b,·c·+·d) - 8 │ + (a·+·b)**(c·+·d) + 8 │ + (a·+·b)·**·(c·+·d) 9 9 │ Math.pow(a = b, c = d) 10 10 │ Math.pow(a += b, c -= d) @@ -203,7 +203,7 @@ invalidBaseExpoentLowerPrecedence.js:9:1 lint/style/useExponentiationOperator F 7 7 │ Math.pow(2, a - b) 8 8 │ Math.pow(a + b, c + d) 9 │ - Math.pow(a·=·b,·c·=·d) - 9 │ + (a·=·b)**(c·=·d) + 9 │ + (a·=·b)·**·(c·=·d) 10 10 │ Math.pow(a += b, c -= d) 11 11 │ Math.pow((a, b), (c, d)) @@ -227,7 +227,7 @@ invalidBaseExpoentLowerPrecedence.js:10:1 lint/style/useExponentiationOperator 8 8 │ Math.pow(a + b, c + d) 9 9 │ Math.pow(a = b, c = d) 10 │ - Math.pow(a·+=·b,·c·-=·d) - 10 │ + (a·+=·b)**(c·-=·d) + 10 │ + (a·+=·b)·**·(c·-=·d) 11 11 │ Math.pow((a, b), (c, d)) 12 12 │ function *f() { Math.pow(yield, yield) } @@ -251,7 +251,7 @@ invalidBaseExpoentLowerPrecedence.js:11:1 lint/style/useExponentiationOperator 9 9 │ Math.pow(a = b, c = d) 10 10 │ Math.pow(a += b, c -= d) 11 │ - Math.pow((a,·b),·(c,·d)) - 11 │ + (a,·b)**(c,·d) + 11 │ + (a,·b)·**·(c,·d) 12 12 │ function *f() { Math.pow(yield, yield) } 13 13 │ @@ -274,7 +274,7 @@ invalidBaseExpoentLowerPrecedence.js:12:17 lint/style/useExponentiationOperator 10 10 │ Math.pow(a += b, c -= d) 11 11 │ Math.pow((a, b), (c, d)) 12 │ - function·*f()·{·Math.pow(yield,·yield)·} - 12 │ + function·*f()·{·(yield)**(yield)·} + 12 │ + function·*f()·{·(yield)·**·(yield)·} 13 13 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidClass.ts.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidClass.ts.snap index 51e2ba5826fa..6f351777e1c3 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidClass.ts.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidClass.ts.snap @@ -28,7 +28,7 @@ invalidClass.ts:2:20 lint/style/useExponentiationOperator FIXABLE ━━━━ 1 1 │ // @ts-nocheck 2 │ - class·C·extends·Math.pow(a,·b)·implements·Foo·{} - 2 │ + class·C·extends·(a**b)·implements·Foo·{} + 2 │ + class·C·extends·(a·**·b)·implements·Foo·{} 3 3 │ (class A extends Math.pow(a, b) implements Foo {}) 4 4 │ (class A extends (Math.pow(a, b)) {}) @@ -52,7 +52,7 @@ invalidClass.ts:3:18 lint/style/useExponentiationOperator FIXABLE ━━━━ 1 1 │ // @ts-nocheck 2 2 │ class C extends Math.pow(a, b) implements Foo {} 3 │ - (class·A·extends·Math.pow(a,·b)·implements·Foo·{}) - 3 │ + (class·A·extends·(a**b)·implements·Foo·{}) + 3 │ + (class·A·extends·(a·**·b)·implements·Foo·{}) 4 4 │ (class A extends (Math.pow(a, b)) {}) 5 5 │ class C extends (Math.pow(a, b)) implements Foo, Bar {} @@ -76,7 +76,7 @@ invalidClass.ts:4:22 lint/style/useExponentiationOperator FIXABLE ━━━━ 2 2 │ class C extends Math.pow(a, b) implements Foo {} 3 3 │ (class A extends Math.pow(a, b) implements Foo {}) 4 │ - (class·A·extends·(Math.pow(a,·b))·{}) - 4 │ + (class·A·extends·(a**b)·{}) + 4 │ + (class·A·extends·(a·**·b)·{}) 5 5 │ class C extends (Math.pow(a, b)) implements Foo, Bar {} 6 6 │ @@ -99,7 +99,7 @@ invalidClass.ts:5:21 lint/style/useExponentiationOperator FIXABLE ━━━━ 3 3 │ (class A extends Math.pow(a, b) implements Foo {}) 4 4 │ (class A extends (Math.pow(a, b)) {}) 5 │ - class·C·extends·(Math.pow(a,·b))·implements·Foo,·Bar·{} - 5 │ + class·C·extends·(a**b)·implements·Foo,·Bar·{} + 5 │ + class·C·extends·(a·**·b)·implements·Foo,·Bar·{} 6 6 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithHigherPrecedence.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithHigherPrecedence.js.snap index 5ed157994e98..215185cffc32 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithHigherPrecedence.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithHigherPrecedence.js.snap @@ -42,7 +42,7 @@ invalidParentsWithHigherPrecedence.js:1:3 lint/style/useExponentiationOperator i Suggested fix: Use the '**' operator instead of 'Math.pow'. 1 │ - +·Math.pow(a,·b); - 1 │ + +·(a**b); + 1 │ + +·(a·**·b); 2 2 │ - Math.pow(a, b); 3 3 │ ! Math.pow(a, b); @@ -64,7 +64,7 @@ invalidParentsWithHigherPrecedence.js:2:3 lint/style/useExponentiationOperator 1 1 │ + Math.pow(a, b); 2 │ - -·Math.pow(a,·b); - 2 │ + -·(a**b); + 2 │ + -·(a·**·b); 3 3 │ ! Math.pow(a, b); 4 4 │ typeof Math.pow(a, b); @@ -88,7 +88,7 @@ invalidParentsWithHigherPrecedence.js:3:3 lint/style/useExponentiationOperator 1 1 │ + Math.pow(a, b); 2 2 │ - Math.pow(a, b); 3 │ - !·Math.pow(a,·b); - 3 │ + !·(a**b); + 3 │ + !·(a·**·b); 4 4 │ typeof Math.pow(a, b); 5 5 │ void Math.pow(a, b); @@ -112,7 +112,7 @@ invalidParentsWithHigherPrecedence.js:4:8 lint/style/useExponentiationOperator 2 2 │ - Math.pow(a, b); 3 3 │ ! Math.pow(a, b); 4 │ - typeof·Math.pow(a,·b); - 4 │ + typeof·(a**b); + 4 │ + typeof·(a·**·b); 5 5 │ void Math.pow(a, b); 6 6 │ Math.pow(a, b) .toString(); @@ -136,7 +136,7 @@ invalidParentsWithHigherPrecedence.js:5:6 lint/style/useExponentiationOperator 3 3 │ ! Math.pow(a, b); 4 4 │ typeof Math.pow(a, b); 5 │ - void·Math.pow(a,·b); - 5 │ + void·(a**b); + 5 │ + void·(a·**·b); 6 6 │ Math.pow(a, b) .toString(); 7 7 │ Math.pow(a, b) (); @@ -160,7 +160,7 @@ invalidParentsWithHigherPrecedence.js:6:1 lint/style/useExponentiationOperator 4 4 │ typeof Math.pow(a, b); 5 5 │ void Math.pow(a, b); 6 │ - Math.pow(a,·b)·.toString(); - 6 │ + (a**b)·.toString(); + 6 │ + (a·**·b)·.toString(); 7 7 │ Math.pow(a, b) (); 8 8 │ Math.pow(a, b) ``; @@ -184,7 +184,7 @@ invalidParentsWithHigherPrecedence.js:7:1 lint/style/useExponentiationOperator 5 5 │ void Math.pow(a, b); 6 6 │ Math.pow(a, b) .toString(); 7 │ - Math.pow(a,·b)·(); - 7 │ + (a**b)·(); + 7 │ + (a·**·b)·(); 8 8 │ Math.pow(a, b) ``; 9 9 │ (class extends Math.pow(a, b) {}) @@ -208,7 +208,7 @@ invalidParentsWithHigherPrecedence.js:8:1 lint/style/useExponentiationOperator 6 6 │ Math.pow(a, b) .toString(); 7 7 │ Math.pow(a, b) (); 8 │ - Math.pow(a,·b)·``; - 8 │ + (a**b)·``; + 8 │ + (a·**·b)·``; 9 9 │ (class extends Math.pow(a, b) {}) 10 10 │ @@ -232,7 +232,7 @@ invalidParentsWithHigherPrecedence.js:9:16 lint/style/useExponentiationOperator 7 7 │ Math.pow(a, b) (); 8 8 │ Math.pow(a, b) ``; 9 │ - (class·extends·Math.pow(a,·b)·{}) - 9 │ + (class·extends·(a**b)·{}) + 9 │ + (class·extends·(a·**·b)·{}) 10 10 │ 11 11 │ // parents with a higher precedence, but the expression's role doesn't require parens @@ -255,7 +255,7 @@ invalidParentsWithHigherPrecedence.js:12:3 lint/style/useExponentiationOperator 10 10 │ 11 11 │ // parents with a higher precedence, but the expression's role doesn't require parens 12 │ - f(Math.pow(a,·b)) - 12 │ + f(a**b) + 12 │ + f(a·**·b) 13 13 │ f(foo, Math.pow(a, b)) 14 14 │ f(Math.pow(a, b), foo) @@ -279,7 +279,7 @@ invalidParentsWithHigherPrecedence.js:13:8 lint/style/useExponentiationOperator 11 11 │ // parents with a higher precedence, but the expression's role doesn't require parens 12 12 │ f(Math.pow(a, b)) 13 │ - f(foo,·Math.pow(a,·b)) - 13 │ + f(foo,·a**b) + 13 │ + f(foo,·a·**·b) 14 14 │ f(Math.pow(a, b), foo) 15 15 │ f(foo, Math.pow(a, b), bar) @@ -303,7 +303,7 @@ invalidParentsWithHigherPrecedence.js:14:3 lint/style/useExponentiationOperator 12 12 │ f(Math.pow(a, b)) 13 13 │ f(foo, Math.pow(a, b)) 14 │ - f(Math.pow(a,·b),·foo) - 14 │ + f(a**b,·foo) + 14 │ + f(a·**·b,·foo) 15 15 │ f(foo, Math.pow(a, b), bar) 16 16 │ new F(Math.pow(a, b)) @@ -327,7 +327,7 @@ invalidParentsWithHigherPrecedence.js:15:8 lint/style/useExponentiationOperator 13 13 │ f(foo, Math.pow(a, b)) 14 14 │ f(Math.pow(a, b), foo) 15 │ - f(foo,·Math.pow(a,·b),·bar) - 15 │ + f(foo,·a**b,·bar) + 15 │ + f(foo,·a·**·b,·bar) 16 16 │ new F(Math.pow(a, b)) 17 17 │ new F(foo, Math.pow(a, b)) @@ -351,7 +351,7 @@ invalidParentsWithHigherPrecedence.js:16:7 lint/style/useExponentiationOperator 14 14 │ f(Math.pow(a, b), foo) 15 15 │ f(foo, Math.pow(a, b), bar) 16 │ - new·F(Math.pow(a,·b)) - 16 │ + new·F(a**b) + 16 │ + new·F(a·**·b) 17 17 │ new F(foo, Math.pow(a, b)) 18 18 │ new F(Math.pow(a, b), foo) @@ -375,7 +375,7 @@ invalidParentsWithHigherPrecedence.js:17:12 lint/style/useExponentiationOperator 15 15 │ f(foo, Math.pow(a, b), bar) 16 16 │ new F(Math.pow(a, b)) 17 │ - new·F(foo,·Math.pow(a,·b)) - 17 │ + new·F(foo,·a**b) + 17 │ + new·F(foo,·a·**·b) 18 18 │ new F(Math.pow(a, b), foo) 19 19 │ new F(foo, Math.pow(a, b), bar) @@ -399,7 +399,7 @@ invalidParentsWithHigherPrecedence.js:18:7 lint/style/useExponentiationOperator 16 16 │ new F(Math.pow(a, b)) 17 17 │ new F(foo, Math.pow(a, b)) 18 │ - new·F(Math.pow(a,·b),·foo) - 18 │ + new·F(a**b,·foo) + 18 │ + new·F(a·**·b,·foo) 19 19 │ new F(foo, Math.pow(a, b), bar) 20 20 │ obj[Math.pow(a, b)] @@ -423,7 +423,7 @@ invalidParentsWithHigherPrecedence.js:19:12 lint/style/useExponentiationOperator 17 17 │ new F(foo, Math.pow(a, b)) 18 18 │ new F(Math.pow(a, b), foo) 19 │ - new·F(foo,·Math.pow(a,·b),·bar) - 19 │ + new·F(foo,·a**b,·bar) + 19 │ + new·F(foo,·a·**·b,·bar) 20 20 │ obj[Math.pow(a, b)] 21 21 │ [foo, Math.pow(a, b), bar] @@ -447,7 +447,7 @@ invalidParentsWithHigherPrecedence.js:20:5 lint/style/useExponentiationOperator 18 18 │ new F(Math.pow(a, b), foo) 19 19 │ new F(foo, Math.pow(a, b), bar) 20 │ - obj[Math.pow(a,·b)] - 20 │ + obj[a**b] + 20 │ + obj[a·**·b] 21 21 │ [foo, Math.pow(a, b), bar] 22 22 │ @@ -470,7 +470,7 @@ invalidParentsWithHigherPrecedence.js:21:7 lint/style/useExponentiationOperator 19 19 │ new F(foo, Math.pow(a, b), bar) 20 20 │ obj[Math.pow(a, b)] 21 │ - [foo,·Math.pow(a,·b),·bar] - 21 │ + [foo,·a**b,·bar] + 21 │ + [foo,·a·**·b,·bar] 22 22 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithLowerPrecedence.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithLowerPrecedence.js.snap index aa018880bf64..295d398dfcf9 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithLowerPrecedence.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidParentsWithLowerPrecedence.js.snap @@ -36,7 +36,7 @@ invalidParentsWithLowerPrecedence.js:2:5 lint/style/useExponentiationOperator F 1 1 │ // parents with a lower precedence 2 │ - a·*·Math.pow(b,·c); - 2 │ + a·*·b**c; + 2 │ + a·*·b·**·c; 3 3 │ Math.pow(a, b) * c; 4 4 │ a + Math.pow(b, c); @@ -60,7 +60,7 @@ invalidParentsWithLowerPrecedence.js:3:1 lint/style/useExponentiationOperator F 1 1 │ // parents with a lower precedence 2 2 │ a * Math.pow(b, c); 3 │ - Math.pow(a,·b)·*·c; - 3 │ + a**b·*·c; + 3 │ + a·**·b·*·c; 4 4 │ a + Math.pow(b, c); 5 5 │ Math.pow(a, b)/c; @@ -84,7 +84,7 @@ invalidParentsWithLowerPrecedence.js:4:5 lint/style/useExponentiationOperator F 2 2 │ a * Math.pow(b, c); 3 3 │ Math.pow(a, b) * c; 4 │ - a·+·Math.pow(b,·c); - 4 │ + a·+·b**c; + 4 │ + a·+·b·**·c; 5 5 │ Math.pow(a, b)/c; 6 6 │ a < Math.pow(b, c); @@ -108,7 +108,7 @@ invalidParentsWithLowerPrecedence.js:5:1 lint/style/useExponentiationOperator F 3 3 │ Math.pow(a, b) * c; 4 4 │ a + Math.pow(b, c); 5 │ - Math.pow(a,·b)/c; - 5 │ + a**b/c; + 5 │ + a·**·b/c; 6 6 │ a < Math.pow(b, c); 7 7 │ Math.pow(a, b) > c; @@ -132,7 +132,7 @@ invalidParentsWithLowerPrecedence.js:6:5 lint/style/useExponentiationOperator F 4 4 │ a + Math.pow(b, c); 5 5 │ Math.pow(a, b)/c; 6 │ - a·<·Math.pow(b,·c); - 6 │ + a·<·b**c; + 6 │ + a·<·b·**·c; 7 7 │ Math.pow(a, b) > c; 8 8 │ a === Math.pow(b, c); @@ -156,7 +156,7 @@ invalidParentsWithLowerPrecedence.js:7:1 lint/style/useExponentiationOperator F 5 5 │ Math.pow(a, b)/c; 6 6 │ a < Math.pow(b, c); 7 │ - Math.pow(a,·b)·>·c; - 7 │ + a**b·>·c; + 7 │ + a·**·b·>·c; 8 8 │ a === Math.pow(b, c); 9 9 │ a ? Math.pow(b, c) : d; @@ -180,7 +180,7 @@ invalidParentsWithLowerPrecedence.js:8:7 lint/style/useExponentiationOperator F 6 6 │ a < Math.pow(b, c); 7 7 │ Math.pow(a, b) > c; 8 │ - a·===·Math.pow(b,·c); - 8 │ + a·===·b**c; + 8 │ + a·===·b·**·c; 9 9 │ a ? Math.pow(b, c) : d; 10 10 │ a = Math.pow(b, c); @@ -204,7 +204,7 @@ invalidParentsWithLowerPrecedence.js:9:5 lint/style/useExponentiationOperator F 7 7 │ Math.pow(a, b) > c; 8 8 │ a === Math.pow(b, c); 9 │ - a·?·Math.pow(b,·c)·:·d; - 9 │ + a·?·b**c·:·d; + 9 │ + a·?·b·**·c·:·d; 10 10 │ a = Math.pow(b, c); 11 11 │ a += Math.pow(b, c); @@ -228,7 +228,7 @@ invalidParentsWithLowerPrecedence.js:10:5 lint/style/useExponentiationOperator 8 8 │ a === Math.pow(b, c); 9 9 │ a ? Math.pow(b, c) : d; 10 │ - a·=·Math.pow(b,·c); - 10 │ + a·=·b**c; + 10 │ + a·=·b·**·c; 11 11 │ a += Math.pow(b, c); 12 12 │ function *f() { yield Math.pow(a, b) } @@ -252,7 +252,7 @@ invalidParentsWithLowerPrecedence.js:11:6 lint/style/useExponentiationOperator 9 9 │ a ? Math.pow(b, c) : d; 10 10 │ a = Math.pow(b, c); 11 │ - a·+=·Math.pow(b,·c); - 11 │ + a·+=·b**c; + 11 │ + a·+=·b·**·c; 12 12 │ function *f() { yield Math.pow(a, b) } 13 13 │ a, Math.pow(b, c), d @@ -276,7 +276,7 @@ invalidParentsWithLowerPrecedence.js:12:23 lint/style/useExponentiationOperator 10 10 │ a = Math.pow(b, c); 11 11 │ a += Math.pow(b, c); 12 │ - function·*f()·{·yield·Math.pow(a,·b)·} - 12 │ + function·*f()·{·yield·a**b·} + 12 │ + function·*f()·{·yield·a·**·b·} 13 13 │ a, Math.pow(b, c), d 14 14 │ @@ -299,7 +299,7 @@ invalidParentsWithLowerPrecedence.js:13:4 lint/style/useExponentiationOperator 11 11 │ a += Math.pow(b, c); 12 12 │ function *f() { yield Math.pow(a, b) } 13 │ - a,·Math.pow(b,·c),·d - 13 │ + a,·b**c,·d + 13 │ + a,·b·**·c,·d 14 14 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidUnaryExpression.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidUnaryExpression.js.snap index 05753e178154..568d84c97f32 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidUnaryExpression.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidUnaryExpression.js.snap @@ -32,7 +32,7 @@ invalidUnaryExpression.js:2:1 lint/style/useExponentiationOperator FIXABLE ━ 1 1 │ // unary expressions are exception by the language - parens are required for the base to disambiguate operator precedence 2 │ - Math.pow(+a,·b) - 2 │ + (+a)**b + 2 │ + (+a)·**·b 3 3 │ Math.pow(a, +b) 4 4 │ Math.pow(-a, b) @@ -56,7 +56,7 @@ invalidUnaryExpression.js:3:1 lint/style/useExponentiationOperator FIXABLE ━ 1 1 │ // unary expressions are exception by the language - parens are required for the base to disambiguate operator precedence 2 2 │ Math.pow(+a, b) 3 │ - Math.pow(a,·+b) - 3 │ + a**+b + 3 │ + a·**·+b 4 4 │ Math.pow(-a, b) 5 5 │ Math.pow(a, -b) @@ -80,7 +80,7 @@ invalidUnaryExpression.js:4:1 lint/style/useExponentiationOperator FIXABLE ━ 2 2 │ Math.pow(+a, b) 3 3 │ Math.pow(a, +b) 4 │ - Math.pow(-a,·b) - 4 │ + (-a)**b + 4 │ + (-a)·**·b 5 5 │ Math.pow(a, -b) 6 6 │ Math.pow(-2, 3) @@ -104,7 +104,7 @@ invalidUnaryExpression.js:5:1 lint/style/useExponentiationOperator FIXABLE ━ 3 3 │ Math.pow(a, +b) 4 4 │ Math.pow(-a, b) 5 │ - Math.pow(a,·-b) - 5 │ + a**-b + 5 │ + a·**·-b 6 6 │ Math.pow(-2, 3) 7 7 │ Math.pow(2, -3) @@ -128,7 +128,7 @@ invalidUnaryExpression.js:6:1 lint/style/useExponentiationOperator FIXABLE ━ 4 4 │ Math.pow(-a, b) 5 5 │ Math.pow(a, -b) 6 │ - Math.pow(-2,·3) - 6 │ + (-2)**3 + 6 │ + (-2)·**·3 7 7 │ Math.pow(2, -3) 8 8 │ async () => Math.pow(await a, b) @@ -152,7 +152,7 @@ invalidUnaryExpression.js:7:1 lint/style/useExponentiationOperator FIXABLE ━ 5 5 │ Math.pow(a, -b) 6 6 │ Math.pow(-2, 3) 7 │ - Math.pow(2,·-3) - 7 │ + 2**-3 + 7 │ + 2·**·-3 8 8 │ async () => Math.pow(await a, b) 9 9 │ async () => Math.pow(a, await b) @@ -176,7 +176,7 @@ invalidUnaryExpression.js:8:13 lint/style/useExponentiationOperator FIXABLE 6 6 │ Math.pow(-2, 3) 7 7 │ Math.pow(2, -3) 8 │ - async·()·=>·Math.pow(await·a,·b) - 8 │ + async·()·=>·(await·a)**b + 8 │ + async·()·=>·(await·a)·**·b 9 9 │ async () => Math.pow(a, await b) 10 10 │ @@ -199,7 +199,7 @@ invalidUnaryExpression.js:9:13 lint/style/useExponentiationOperator FIXABLE 7 7 │ Math.pow(2, -3) 8 8 │ async () => Math.pow(await a, b) 9 │ - async·()·=>·Math.pow(a,·await·b) - 9 │ + async·()·=>·a**await·b + 9 │ + async·()·=>·a·**·await·b 10 10 │ diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js new file mode 100644 index 000000000000..0564ab30daff --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js @@ -0,0 +1,7 @@ +/* comment */Math.pow(a, b) +Math.pow(a, b)/* comment */; +Math.pow(a, b)// comment + +Math.pow(/**/a/**/, /**/b/**/) + +Math/**/.pow/**/(a, b) diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js.snap new file mode 100644 index 000000000000..38ae5a75d140 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithComments.js.snap @@ -0,0 +1,130 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: invalidWithComments.js +--- +# Input +```js +/* comment */Math.pow(a, b) +Math.pow(a, b)/* comment */; +Math.pow(a, b)// comment + +Math.pow(/**/a/**/, /**/b/**/) + +Math/**/.pow/**/(a, b) + +``` + +# Diagnostics +``` +invalidWithComments.js:1:14 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use the '**' operator instead of 'Math.pow'. + + > 1 │ /* comment */Math.pow(a, b) + │ ^^^^^^^^^^^^^^ + 2 │ Math.pow(a, b)/* comment */; + 3 │ Math.pow(a, b)// comment + + i Suggested fix: Use the '**' operator instead of 'Math.pow'. + + 1 │ - /*·comment·*/Math.pow(a,·b) + 1 │ + /*·comment·*/a·**·b + 2 2 │ Math.pow(a, b)/* comment */; + 3 3 │ Math.pow(a, b)// comment + + +``` + +``` +invalidWithComments.js:2:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use the '**' operator instead of 'Math.pow'. + + 1 │ /* comment */Math.pow(a, b) + > 2 │ Math.pow(a, b)/* comment */; + │ ^^^^^^^^^^^^^^ + 3 │ Math.pow(a, b)// comment + 4 │ + + i Suggested fix: Use the '**' operator instead of 'Math.pow'. + + 1 1 │ /* comment */Math.pow(a, b) + 2 │ - Math.pow(a,·b)/*·comment·*/; + 2 │ + a·**·b/*·comment·*/; + 3 3 │ Math.pow(a, b)// comment + 4 4 │ + + +``` + +``` +invalidWithComments.js:3:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use the '**' operator instead of 'Math.pow'. + + 1 │ /* comment */Math.pow(a, b) + 2 │ Math.pow(a, b)/* comment */; + > 3 │ Math.pow(a, b)// comment + │ ^^^^^^^^^^^^^^ + 4 │ + 5 │ Math.pow(/**/a/**/, /**/b/**/) + + i Suggested fix: Use the '**' operator instead of 'Math.pow'. + + 1 1 │ /* comment */Math.pow(a, b) + 2 2 │ Math.pow(a, b)/* comment */; + 3 │ - Math.pow(a,·b)//·comment + 3 │ + a·**·b//·comment + 4 4 │ + 5 5 │ Math.pow(/**/a/**/, /**/b/**/) + + +``` + +``` +invalidWithComments.js:5:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use the '**' operator instead of 'Math.pow'. + + 3 │ Math.pow(a, b)// comment + 4 │ + > 5 │ Math.pow(/**/a/**/, /**/b/**/) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 6 │ + 7 │ Math/**/.pow/**/(a, b) + + i Suggested fix: Use the '**' operator instead of 'Math.pow'. + + 3 3 │ Math.pow(a, b)// comment + 4 4 │ + 5 │ - Math.pow(/**/a/**/,·/**/b/**/) + 5 │ + /**/a/**/·**·/**/b/**/ + 6 6 │ + 7 7 │ Math/**/.pow/**/(a, b) + + +``` + +``` +invalidWithComments.js:7:1 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use the '**' operator instead of 'Math.pow'. + + 5 │ Math.pow(/**/a/**/, /**/b/**/) + 6 │ + > 7 │ Math/**/.pow/**/(a, b) + │ ^^^^^^^^^^^^^^^^^^^^^^ + 8 │ + + i Suggested fix: Use the '**' operator instead of 'Math.pow'. + + 5 5 │ Math.pow(/**/a/**/, /**/b/**/) + 6 6 │ + 7 │ - Math/**/.pow/**/(a,·b) + 7 │ + a·**·b + 8 8 │ + + +``` + + diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js index 83287ea52ff9..48cd96d97259 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js @@ -9,11 +9,3 @@ Math.pow(...a) Math.pow(...a, b) Math.pow(a, ...b) Math.pow(a, b, ...c) - -// shouldn't autofix if that would remove comments -/* comment */Math.pow(a, b) -Math.pow(/**/a, b) -Math.pow(a, b/**/) -Math.pow(a, b)/* comment */; -Math.pow(a, b)// comment; -Math.pow(/**/a/**/, /**/b/**/) diff --git a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js.snap b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js.snap index 9fbb3cf42030..7444b2f8b258 100644 --- a/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js.snap +++ b/crates/rome_js_analyze/tests/specs/style/useExponentiationOperator/invalidWithoutAutofix.js.snap @@ -16,14 +16,6 @@ Math.pow(...a, b) Math.pow(a, ...b) Math.pow(a, b, ...c) -// shouldn't autofix if that would remove comments -/* comment */Math.pow(a, b) -Math.pow(/**/a, b) -Math.pow(a, b/**/) -Math.pow(a, b)/* comment */; -Math.pow(a, b)// comment; -Math.pow(/**/a/**/, /**/b/**/) - ``` # Diagnostics @@ -140,104 +132,6 @@ invalidWithoutAutofix.js:11:1 lint/style/useExponentiationOperator ━━━━ > 11 │ Math.pow(a, b, ...c) │ ^^^^^^^^^^^^^^^^^^^^ 12 │ - 13 │ // shouldn't autofix if that would remove comments - - -``` - -``` -invalidWithoutAutofix.js:14:14 lint/style/useExponentiationOperator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 13 │ // shouldn't autofix if that would remove comments - > 14 │ /* comment */Math.pow(a, b) - │ ^^^^^^^^^^^^^^ - 15 │ Math.pow(/**/a, b) - 16 │ Math.pow(a, b/**/) - - i Suggested fix: Use the '**' operator instead of 'Math.pow'. - - 12 12 │ - 13 13 │ // shouldn't autofix if that would remove comments - 14 │ - /*·comment·*/Math.pow(a,·b) - 14 │ + /*·comment·*/a**b - 15 15 │ Math.pow(/**/a, b) - 16 16 │ Math.pow(a, b/**/) - - -``` - -``` -invalidWithoutAutofix.js:15:1 lint/style/useExponentiationOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 13 │ // shouldn't autofix if that would remove comments - 14 │ /* comment */Math.pow(a, b) - > 15 │ Math.pow(/**/a, b) - │ ^^^^^^^^^^^^^^^^^^ - 16 │ Math.pow(a, b/**/) - 17 │ Math.pow(a, b)/* comment */; - - -``` - -``` -invalidWithoutAutofix.js:16:1 lint/style/useExponentiationOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 14 │ /* comment */Math.pow(a, b) - 15 │ Math.pow(/**/a, b) - > 16 │ Math.pow(a, b/**/) - │ ^^^^^^^^^^^^^^^^^^ - 17 │ Math.pow(a, b)/* comment */; - 18 │ Math.pow(a, b)// comment; - - -``` - -``` -invalidWithoutAutofix.js:17:1 lint/style/useExponentiationOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 15 │ Math.pow(/**/a, b) - 16 │ Math.pow(a, b/**/) - > 17 │ Math.pow(a, b)/* comment */; - │ ^^^^^^^^^^^^^^ - 18 │ Math.pow(a, b)// comment; - 19 │ Math.pow(/**/a/**/, /**/b/**/) - - -``` - -``` -invalidWithoutAutofix.js:18:1 lint/style/useExponentiationOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 16 │ Math.pow(a, b/**/) - 17 │ Math.pow(a, b)/* comment */; - > 18 │ Math.pow(a, b)// comment; - │ ^^^^^^^^^^^^^^ - 19 │ Math.pow(/**/a/**/, /**/b/**/) - 20 │ - - -``` - -``` -invalidWithoutAutofix.js:19:1 lint/style/useExponentiationOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Use the '**' operator instead of 'Math.pow'. - - 17 │ Math.pow(a, b)/* comment */; - 18 │ Math.pow(a, b)// comment; - > 19 │ Math.pow(/**/a/**/, /**/b/**/) - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 20 │ ``` diff --git a/crates/rome_js_factory/src/make.rs b/crates/rome_js_factory/src/make.rs index 9356f44add5d..3108a62c9375 100644 --- a/crates/rome_js_factory/src/make.rs +++ b/crates/rome_js_factory/src/make.rs @@ -1,6 +1,8 @@ use std::fmt::Display; -use rome_js_syntax::{JsSyntaxKind, JsSyntaxToken, TriviaPieceKind}; +use rome_js_syntax::{ + AnyJsExpression, JsParenthesizedExpression, JsSyntaxKind, JsSyntaxToken, TriviaPieceKind, +}; use rome_rowan::TriviaPiece; pub use crate::generated::node_factory::*; @@ -78,6 +80,16 @@ pub fn token_decorated_with_space(kind: JsSyntaxKind) -> JsSyntaxToken { } } +/// EOF token pub fn eof() -> JsSyntaxToken { JsSyntaxToken::new_detached(JsSyntaxKind::EOF, "", [], []) } + +/// Wrap `expr` in a new parenthesized expression +pub fn parenthesized(expr: impl Into) -> JsParenthesizedExpression { + js_parenthesized_expression( + token(JsSyntaxKind::L_PAREN), + expr.into(), + token(JsSyntaxKind::R_PAREN), + ) +} diff --git a/crates/rome_js_syntax/src/expr_ext.rs b/crates/rome_js_syntax/src/expr_ext.rs index b0e427492da6..b0ed3fd04bd6 100644 --- a/crates/rome_js_syntax/src/expr_ext.rs +++ b/crates/rome_js_syntax/src/expr_ext.rs @@ -17,7 +17,6 @@ use rome_rowan::{ declare_node_union, AstNode, AstNodeList, AstSeparatedList, NodeOrToken, SyntaxResult, TextRange, TokenText, }; -use std::collections::HashSet; const GLOBAL_THIS: &str = "globalThis"; const UNDEFINED: &str = "undefined"; @@ -1099,7 +1098,7 @@ impl JsCallExpression { /// Each index inside "indices" should be unique. /// "indices" must be sorted. /// - /// Supports maximum of 16 indices to avoid stack overflow. Eeach argument will consume: + /// Supports maximum of 16 indices to avoid stack overflow. Each argument will consume: /// /// - 8 bytes for the `Option` result; /// - 8 bytes for the [usize] argument. @@ -1107,21 +1106,13 @@ impl JsCallExpression { &self, indices: [usize; N], ) -> [Option; N] { - // assert there are no duplicates - debug_assert!(HashSet::<_>::from_iter(indices).len() == N); - debug_assert!({ - // is_sorted is unstable - let mut sorted = indices; - sorted.sort(); - indices == sorted - }); debug_assert!(N <= 16); + // assert there are no duplicates and they are in-order + debug_assert!(indices.windows(2).all(|vs| vs[0] < vs[1])); const INIT: Option = None; let mut results = [INIT; N]; - let mut next = 0; - for (i, arg) in self .arguments() .ok() @@ -1133,9 +1124,11 @@ impl JsCallExpression { if i == indices[next] { results[next] = arg.ok(); next += 1; + if next == N { + break; + } } } - results } diff --git a/website/src/content/docs/linter/rules/use-exponentiation-operator.md b/website/src/content/docs/linter/rules/use-exponentiation-operator.md index 7b90e9e28245..f2f43f91b985 100644 --- a/website/src/content/docs/linter/rules/use-exponentiation-operator.md +++ b/website/src/content/docs/linter/rules/use-exponentiation-operator.md @@ -9,10 +9,9 @@ This rule is recommended by Biome. A diagnostic error will appear when linting y Disallow the use of `Math.pow` in favor of the `**` operator. ->Introduced in ES2016, the infix exponentiation operator ** is an alternative for the standard Math.pow function. +Introduced in ES2016, the infix exponentiation operator `**` is an alternative for the standard `Math.pow` function. Infix notation is considered to be more readable and thus more preferable than the function notation. - Source: https://eslint.org/docs/latest/rules/prefer-exponentiation-operator ## Examples @@ -33,8 +32,8 @@ const foo = Math.pow(2, 8); Suggested fix: Use the '**' operator instead of 'Math.pow'. - 1 - const·foo·=·Math.pow(2,·8); - 1+ const·foo·=·2**8; + 1 - const·foo·=·Math.pow(2,·8); + 1+ const·foo·=·2·**·8; 2 2 @@ -53,8 +52,8 @@ const bar = Math.pow(a, b); Suggested fix: Use the '**' operator instead of 'Math.pow'. - 1 - const·bar·=·Math.pow(a,·b); - 1+ const·bar·=·a**b; + 1 - const·bar·=·Math.pow(a,·b); + 1+ const·bar·=·a·**·b; 2 2 @@ -73,8 +72,8 @@ let baz = Math.pow(a + b, c + d); Suggested fix: Use the '**' operator instead of 'Math.pow'. - 1 - let·baz·=·Math.pow(a·+·b,·c·+·d); - 1+ let·baz·=·(a·+·b)**(c·+·d); + 1 - let·baz·=·Math.pow(a·+·b,·c·+·d); + 1+ let·baz·=·(a·+·b)·**·(c·+·d); 2 2 @@ -93,8 +92,8 @@ let quux = Math.pow(-1, n); Suggested fix: Use the '**' operator instead of 'Math.pow'. - 1 - let·quux·=·Math.pow(-1,·n); - 1+ let·quux·=·(-1)**n; + 1 - let·quux·=·Math.pow(-1,·n); + 1+ let·quux·=·(-1)·**·n; 2 2 diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 6f8dc7c84bcb..57d8c2b3c841 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "xtask" -version = "0.0.0" edition = "2021" +name = "xtask" publish = false +version = "0.0.0" [dependencies] anyhow = "1.0.52" diff --git a/xtask/bench/Cargo.toml b/xtask/bench/Cargo.toml index 2b5deb7f3407..f13ae2f8be90 100644 --- a/xtask/bench/Cargo.toml +++ b/xtask/bench/Cargo.toml @@ -1,39 +1,39 @@ [package] -name = "xtask_bench" -version = "0.0.0" edition = "2021" +name = "xtask_bench" publish = false +version = "0.0.0" [dependencies] -xtask = { path = '../', version = "0.0" } -rome_js_syntax = { path = "../../crates/rome_js_syntax" } -rome_console = { path = "../../crates/rome_console" } -rome_js_parser = { path = "../../crates/rome_js_parser" } +rome_analyze = { path = "../../crates/rome_analyze" } +rome_console = { path = "../../crates/rome_console" } +rome_diagnostics = { path = "../../crates/rome_diagnostics" } +rome_formatter = { path = "../../crates/rome_formatter" } +rome_js_analyze = { path = "../../crates/rome_js_analyze" } +rome_js_formatter = { path = "../../crates/rome_js_formatter" } +rome_js_parser = { path = "../../crates/rome_js_parser" } +rome_js_syntax = { path = "../../crates/rome_js_syntax" } rome_json_formatter = { path = "../../crates/rome_json_formatter" } -rome_json_parser = { path = "../../crates/rome_json_parser" } -rome_json_syntax = { path = "../../crates/rome_json_syntax" } -rome_parser = { path = "../../crates/rome_parser" } -rome_diagnostics = { path = "../../crates/rome_diagnostics" } -rome_formatter = { path = "../../crates/rome_formatter" } -rome_js_formatter = { path = "../../crates/rome_js_formatter" } -rome_analyze = { path = "../../crates/rome_analyze" } -rome_js_analyze = { path = "../../crates/rome_js_analyze" } -rome_rowan = { path = "../../crates/rome_rowan" } +rome_json_parser = { path = "../../crates/rome_json_parser" } +rome_json_syntax = { path = "../../crates/rome_json_syntax" } +rome_parser = { path = "../../crates/rome_parser" } +rome_rowan = { path = "../../crates/rome_rowan" } +xtask = { path = '../', version = "0.0" } -pico-args = { version = "0.5.0", features = ["eq-separator"] } -timing = "0.2.3" +ansi_rgb = "0.2.0" criterion = "0.5.1" -regex = "1.5.5" -ureq = "2.7.1" -url = "2.2.2" itertools = "0.11.0" -ansi_rgb = "0.2.0" +pico-args = { version = "0.5.0", features = ["eq-separator"] } +regex = "1.5.5" +timing = "0.2.3" +ureq = "2.7.1" +url = "2.2.2" countme = { workspace = true } # dhat-on -dhat = { version = "0.3.0", optional = true } +dhat = { version = "0.3.0", optional = true } humansize = { version = "2.1.2", optional = true } [target.'cfg(target_os = "windows")'.dependencies] @@ -43,5 +43,5 @@ mimalloc = "0.1.29" tikv-jemallocator = "0.5.0" [features] +count = ["countme/print_at_exit"] dhat-heap = ["dhat", "humansize"] -count = ["countme/print_at_exit"] diff --git a/xtask/codegen/Cargo.toml b/xtask/codegen/Cargo.toml index f9ab96dd588b..3ba95088a153 100644 --- a/xtask/codegen/Cargo.toml +++ b/xtask/codegen/Cargo.toml @@ -1,44 +1,42 @@ [package] -name = "xtask_codegen" -version = "0.0.0" edition = "2021" +name = "xtask_codegen" publish = false +version = "0.0.0" [dependencies] -xtask = { path = '../', version = "0.0" } -anyhow = "1.0.52" -pico-args = { version = "0.5.0", features = ["eq-separator"] } -quote = "1.0.14" -proc-macro2 = { version = "1.0.63", features = ["span-locations"] } -ungrammar = "1.14.9" -walkdir = "2.3.2" -ureq = "2.4.0" -git2 = { version = "0.17.1", default-features = false } -filetime = "0.2.15" -case = "1.0.0" -convert_case = "0.6.0" +anyhow = "1.0.52" +case = "1.0.0" +convert_case = "0.6.0" +filetime = "0.2.15" +fs_extra = "1.3.0" +git2 = { version = "0.17.1", default-features = false } +pico-args = { version = "0.5.0", features = ["eq-separator"] } +proc-macro2 = { version = "1.0.63", features = ["span-locations"] } pulldown-cmark = { version = "0.9", default-features = false, optional = true } -fs_extra = "1.3.0" +quote = "1.0.14" +ungrammar = "1.14.9" +ureq = "2.4.0" +walkdir = "2.3.2" +xtask = { path = '../', version = "0.0" } -rome_js_parser = { workspace = true, optional = true } -rome_rowan = { path = "../../crates/rome_rowan", optional = true } -rome_cli = { workspace = true, optional = true } -rome_analyze = { path = "../../crates/rome_analyze", optional = true } -rome_js_analyze = { path = "../../crates/rome_js_analyze", optional = true } -rome_json_analyze = { workspace = true, optional = true } -rome_js_syntax = { path = "../../crates/rome_js_syntax", optional = true } -rome_json_syntax = { workspace = true, optional = true } -rome_js_factory = { path = "../../crates/rome_js_factory", optional = true } -rome_js_formatter = { path = "../../crates/rome_js_formatter", optional = true } +rome_analyze = { path = "../../crates/rome_analyze", optional = true } +rome_aria = { path = "../../crates/rome_aria", optional = true } +rome_cli = { workspace = true, optional = true } +rome_diagnostics = { path = "../../crates/rome_diagnostics", optional = true } +rome_js_analyze = { path = "../../crates/rome_js_analyze", optional = true } +rome_js_factory = { path = "../../crates/rome_js_factory", optional = true } +rome_js_formatter = { path = "../../crates/rome_js_formatter", optional = true } +rome_js_parser = { workspace = true, optional = true } +rome_js_syntax = { path = "../../crates/rome_js_syntax", optional = true } +rome_json_analyze = { workspace = true, optional = true } rome_json_formatter = { path = "../../crates/rome_json_formatter", optional = true } -rome_json_parser = { path = "../../crates/rome_json_parser", optional = true } -rome_diagnostics = { path = "../../crates/rome_diagnostics", optional = true } -rome_aria = { path = "../../crates/rome_aria", optional = true } -rome_service = { path = "../../crates/rome_service", features = [ - "schema", -], optional = true } -schemars = { version = "0.8.10", optional = true } -serde_json = { version = "1.0.74", optional = true } +rome_json_parser = { path = "../../crates/rome_json_parser", optional = true } +rome_json_syntax = { workspace = true, optional = true } +rome_rowan = { path = "../../crates/rome_rowan", optional = true } +rome_service = { path = "../../crates/rome_service", features = ["schema"], optional = true } +schemars = { version = "0.8.10", optional = true } +serde_json = { version = "1.0.74", optional = true } [features] configuration = [ @@ -49,7 +47,6 @@ configuration = [ "rome_json_syntax", "pulldown-cmark", ] -website = ["rome_service", "rome_cli/docgen", "rome_js_parser", "rome_js_formatter", "rome_js_syntax"] schema = [ "schemars", "serde_json", @@ -62,3 +59,4 @@ schema = [ "rome_json_parser", "rome_diagnostics", ] +website = ["rome_service", "rome_cli/docgen", "rome_js_parser", "rome_js_formatter", "rome_js_syntax"] diff --git a/xtask/contributors/Cargo.toml b/xtask/contributors/Cargo.toml index 2be232fa65cc..3ac3087bfddd 100644 --- a/xtask/contributors/Cargo.toml +++ b/xtask/contributors/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "xtask_contributors" -version = "0.0.0" edition = "2021" +name = "xtask_contributors" publish = false +version = "0.0.0" [dependencies] -serde = { version = "1.0.133", features = ["derive"] } -serde_json = { version = "1.0.74" } -xtask = { path = '../', version = "0.0" } -ureq = { version = "2.4.0", features = ["json"] } -pico-args = "0.5.0" html-escape = "0.2.11" +pico-args = "0.5.0" +serde = { version = "1.0.133", features = ["derive"] } +serde_json = { version = "1.0.74" } +ureq = { version = "2.4.0", features = ["json"] } +xtask = { path = '../', version = "0.0" } diff --git a/xtask/coverage/Cargo.toml b/xtask/coverage/Cargo.toml index ebe58368e46b..c96998f313f9 100644 --- a/xtask/coverage/Cargo.toml +++ b/xtask/coverage/Cargo.toml @@ -1,30 +1,30 @@ [package] -name = "xtask_coverage" -version = "0.0.0" edition = "2021" +name = "xtask_coverage" publish = false +version = "0.0.0" [dependencies] -xtask = { path = '../', version = "0.0" } -rome_rowan = { path = "../../crates/rome_rowan" } -rome_console = { path = "../../crates/rome_console" } -rome_js_syntax = { path = "../../crates/rome_js_syntax" } -rome_js_parser = { path = "../../crates/rome_js_parser" } -rome_js_semantic = { path = "../../crates/rome_js_semantic" } -rome_diagnostics = { path = "../../crates/rome_diagnostics" } -rome_parser = { path = "../../crates/rome_parser" } -pico-args = { version = "0.5.0", features = ["eq-separator"] } -ascii_table = "4.0.2" -colored = "2.0.0" -yastl = "0.1.2" -indicatif = { version = "0.17.0", features = ["improved_unicode"] } -serde = { version = "1.0.133", features = ["derive"] } -serde_json = "1.0.74" -serde_yaml = "0.9.9" -regex = "1.5.5" -once_cell = "1.9.0" -walkdir = "2.3.2" -atty = { workspace = true } -tracing = { workspace = true } +ascii_table = "4.0.2" +atty = { workspace = true } +backtrace = "0.3.65" +colored = "2.0.0" +indicatif = { version = "0.17.0", features = ["improved_unicode"] } +once_cell = "1.9.0" +pico-args = { version = "0.5.0", features = ["eq-separator"] } +regex = "1.5.5" +rome_console = { path = "../../crates/rome_console" } +rome_diagnostics = { path = "../../crates/rome_diagnostics" } +rome_js_parser = { path = "../../crates/rome_js_parser" } +rome_js_semantic = { path = "../../crates/rome_js_semantic" } +rome_js_syntax = { path = "../../crates/rome_js_syntax" } +rome_parser = { path = "../../crates/rome_parser" } +rome_rowan = { path = "../../crates/rome_rowan" } +serde = { version = "1.0.133", features = ["derive"] } +serde_json = "1.0.74" +serde_yaml = "0.9.9" +tracing = { workspace = true } tracing-subscriber = { version = "0.3.11", features = ["env-filter", "std"] } -backtrace = "0.3.65" +walkdir = "2.3.2" +xtask = { path = '../', version = "0.0" } +yastl = "0.1.2" diff --git a/xtask/libs_bench/Cargo.toml b/xtask/libs_bench/Cargo.toml index e23737ab59d4..f51bbc9093cb 100644 --- a/xtask/libs_bench/Cargo.toml +++ b/xtask/libs_bench/Cargo.toml @@ -1,36 +1,36 @@ [package] -name = "xtask_libs_bench" -version = "0.0.0" edition = "2021" +name = "xtask_libs_bench" publish = false +version = "0.0.0" [dependencies] regex = { version = "1.6.0" } [dev-dependencies] +case = "1.0.0" +criterion = "0.4.0" +fastbloom-rs = "0.3.0" +fst = "0.4.7" +iai = "0.1.1" +memchr = "2.5.0" +qp-trie = "0.8.0" rome_js_analyze = { path = "../../crates/rome_js_analyze" } -case = "1.0.0" -fastbloom-rs = "0.3.0" -qp-trie = "0.8.0" -fst = "0.4.7" -criterion = "0.4.0" -memchr = "2.5.0" -iai = "0.1.1" [[bench]] -name = "to_camel_case" harness = false +name = "to_camel_case" [[bench]] -name = "contains_iai" harness = false +name = "contains_iai" [[bench]] -name = "contains_criterion" harness = false +name = "contains_criterion" [[bin]] -name = "contains_iai" -path = "bins/contains_iai.rs" -test = false bench = false +name = "contains_iai" +path = "bins/contains_iai.rs" +test = false diff --git a/xtask/lintdoc/Cargo.toml b/xtask/lintdoc/Cargo.toml index 7e5cff85719d..0338f2acc247 100644 --- a/xtask/lintdoc/Cargo.toml +++ b/xtask/lintdoc/Cargo.toml @@ -1,21 +1,21 @@ [package] -name = "xtask_lintdoc" -version = "0.0.0" edition = "2021" +name = "xtask_lintdoc" publish = false +version = "0.0.0" [dependencies] -xtask = { path = '../', version = "0.0" } -rome_analyze = { path = "../../crates/rome_analyze" } -rome_console = { path = "../../crates/rome_console" } -rome_diagnostics = { path = "../../crates/rome_diagnostics" } -rome_js_analyze = { path = "../../crates/rome_js_analyze" } +convert_case = "0.6.0" +pulldown-cmark = { version = "0.9", default-features = false } +rome_analyze = { path = "../../crates/rome_analyze" } +rome_console = { path = "../../crates/rome_console" } +rome_diagnostics = { path = "../../crates/rome_diagnostics" } +rome_formatter = { path = "../../crates/rome_formatter" } +rome_js_analyze = { path = "../../crates/rome_js_analyze" } +rome_js_parser = { path = "../../crates/rome_js_parser" } +rome_js_syntax = { path = "../../crates/rome_js_syntax" } rome_json_analyze = { path = "../../crates/rome_json_analyze" } -rome_js_parser = { path = "../../crates/rome_js_parser" } -rome_js_syntax = { path = "../../crates/rome_js_syntax" } -rome_json_parser = { path = "../../crates/rome_json_parser" } -rome_json_syntax = { path = "../../crates/rome_json_syntax" } -rome_service = { path = "../../crates/rome_service" } -rome_formatter = { path = "../../crates/rome_formatter" } -pulldown-cmark = { version = "0.9", default-features = false } -convert_case = "0.6.0" +rome_json_parser = { path = "../../crates/rome_json_parser" } +rome_json_syntax = { path = "../../crates/rome_json_syntax" } +rome_service = { path = "../../crates/rome_service" } +xtask = { path = '../', version = "0.0" }