Skip to content

Commit

Permalink
refactor: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Dec 27, 2024
1 parent 106875a commit e43a759
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ declare_oxc_lint!(
impl Rule for NoNestedTernary {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
if let AstKind::ConditionalExpression(node) = node.kind() {
let check_nested_ternary = |expr: &Expression| {
if matches!(expr, Expression::ConditionalExpression(_)) {
true
} else {
let inner_expr = expr.get_inner_expression();
matches!(inner_expr, Expression::ConditionalExpression(_))
}
};

if check_nested_ternary(&node.consequent) || check_nested_ternary(&node.alternate) {
if matches!(
node.consequent.get_inner_expression(),
Expression::ConditionalExpression(_)
) || matches!(
node.alternate.get_inner_expression(),
Expression::ConditionalExpression(_)
) {
ctx.diagnostic(no_nested_ternary_diagnostic(node.span));
}
}
Expand Down

0 comments on commit e43a759

Please sign in to comment.