Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter) Fix prefer logical operator error with parenthesis #1241

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
_ => {}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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