mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(linter) Fix prefer logical operator error with parenthesis (#1241)
This commit is contained in:
parent
80f3d13761
commit
9f653881bb
2 changed files with 30 additions and 0 deletions
|
|
@ -88,6 +88,12 @@ fn is_same_node(left: &Expression, right: &Expression, ctx: &LintContext) -> boo
|
|||
Expression::UnaryExpression(right_await_expr),
|
||||
) => return is_same_node(&left_await_expr.argument, &right_await_expr.argument, ctx),
|
||||
(Expression::UpdateExpression(_), Expression::UpdateExpression(_)) => return false,
|
||||
(Expression::ParenthesizedExpression(left_paren_expr), _) => {
|
||||
return is_same_node(&left_paren_expr.expression, right, ctx)
|
||||
}
|
||||
(_, Expression::ParenthesizedExpression(right_paren_expr)) => {
|
||||
return is_same_node(left, &right_paren_expr.expression, ctx);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
@ -201,6 +207,9 @@ fn test() {
|
|||
"a ?? b ? a ?? b : bar",
|
||||
"foo ? foo : await a",
|
||||
"await a ? await a : foo",
|
||||
"await a ? (await (a)) : (foo)",
|
||||
"(await a) ? await (a) : (foo)",
|
||||
"(await a) ? (await (a)) : (foo)",
|
||||
];
|
||||
|
||||
Tester::new_without_config(PreferLogicalOperatorOverTernary::NAME, pass, fail)
|
||||
|
|
|
|||
|
|
@ -107,4 +107,25 @@ expression: prefer_logical_operator_over_ternary
|
|||
╰────
|
||||
help: Switch to "||" or "??" operator
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-logical-operator-over-ternary): Prefer using a logical operator over a ternary.
|
||||
╭─[prefer_logical_operator_over_ternary.tsx:1:1]
|
||||
1 │ await a ? (await (a)) : (foo)
|
||||
· ─────────────────────────────
|
||||
╰────
|
||||
help: Switch to "||" or "??" operator
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-logical-operator-over-ternary): Prefer using a logical operator over a ternary.
|
||||
╭─[prefer_logical_operator_over_ternary.tsx:1:1]
|
||||
1 │ (await a) ? await (a) : (foo)
|
||||
· ─────────────────────────────
|
||||
╰────
|
||||
help: Switch to "||" or "??" operator
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-logical-operator-over-ternary): Prefer using a logical operator over a ternary.
|
||||
╭─[prefer_logical_operator_over_ternary.tsx:1:1]
|
||||
1 │ (await a) ? (await (a)) : (foo)
|
||||
· ───────────────────────────────
|
||||
╰────
|
||||
help: Switch to "||" or "??" operator
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue