Skip to content

Commit c8d775c

Browse files
committed
perf(linter): refactor jest/no-conditional-in-test to use diverging match (#14692)
Use diverging `match node.kind()` instead of `if !matches!(node.kind(), ...)`
1 parent b666c26 commit c8d775c

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,12 @@ impl RuleRunner for crate::rules::jest::no_conditional_expect::NoConditionalExpe
12261226
}
12271227

12281228
impl RuleRunner for crate::rules::jest::no_conditional_in_test::NoConditionalInTest {
1229-
const NODE_TYPES: Option<&AstTypesBitset> = None;
1229+
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
1230+
AstType::ConditionalExpression,
1231+
AstType::IfStatement,
1232+
AstType::LogicalExpression,
1233+
AstType::SwitchStatement,
1234+
]));
12301235
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
12311236
}
12321237

crates/oxc_linter/src/rules/jest/no_conditional_in_test.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,36 +99,36 @@ declare_oxc_lint!(
9999

100100
impl Rule for NoConditionalInTest {
101101
fn run<'a>(&self, node: &oxc_semantic::AstNode<'a>, ctx: &LintContext<'a>) {
102-
if matches!(
103-
node.kind(),
102+
match node.kind() {
104103
AstKind::IfStatement(_)
105-
| AstKind::SwitchStatement(_)
106-
| AstKind::ConditionalExpression(_)
107-
| AstKind::LogicalExpression(_)
108-
) {
109-
let is_if_statement_in_test = ctx.nodes().ancestors(node.id()).any(|node| {
110-
let AstKind::CallExpression(call_expr) = node.kind() else { return false };
111-
let vitest_node = PossibleJestNode { node, original: None };
104+
| AstKind::SwitchStatement(_)
105+
| AstKind::ConditionalExpression(_)
106+
| AstKind::LogicalExpression(_) => {}
107+
_ => return,
108+
}
109+
110+
let is_if_statement_in_test = ctx.nodes().ancestors(node.id()).any(|node| {
111+
let AstKind::CallExpression(call_expr) = node.kind() else { return false };
112+
let vitest_node = PossibleJestNode { node, original: None };
112113

113-
is_type_of_jest_fn_call(
114-
call_expr,
115-
&vitest_node,
116-
ctx,
117-
&[JestFnKind::General(crate::utils::JestGeneralFnKind::Test)],
118-
)
119-
});
114+
is_type_of_jest_fn_call(
115+
call_expr,
116+
&vitest_node,
117+
ctx,
118+
&[JestFnKind::General(crate::utils::JestGeneralFnKind::Test)],
119+
)
120+
});
120121

121-
if is_if_statement_in_test {
122-
let span = match node.kind() {
123-
AstKind::IfStatement(stmt) => stmt.span,
124-
AstKind::SwitchStatement(stmt) => stmt.span,
125-
AstKind::ConditionalExpression(expr) => expr.span,
126-
AstKind::LogicalExpression(expr) => expr.span,
127-
_ => unreachable!(),
128-
};
122+
if is_if_statement_in_test {
123+
let span = match node.kind() {
124+
AstKind::IfStatement(stmt) => stmt.span,
125+
AstKind::SwitchStatement(stmt) => stmt.span,
126+
AstKind::ConditionalExpression(expr) => expr.span,
127+
AstKind::LogicalExpression(expr) => expr.span,
128+
_ => unreachable!(),
129+
};
129130

130-
ctx.diagnostic(no_conditional_in_test(span));
131-
}
131+
ctx.diagnostic(no_conditional_in_test(span));
132132
}
133133
}
134134
}

0 commit comments

Comments
 (0)