Skip to content
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
7 changes: 6 additions & 1 deletion crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,12 @@ impl RuleRunner for crate::rules::jest::no_conditional_expect::NoConditionalExpe
}

impl RuleRunner for crate::rules::jest::no_conditional_in_test::NoConditionalInTest {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
AstType::ConditionalExpression,
AstType::IfStatement,
AstType::LogicalExpression,
AstType::SwitchStatement,
]));
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

Expand Down
52 changes: 26 additions & 26 deletions crates/oxc_linter/src/rules/jest/no_conditional_in_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,36 @@ declare_oxc_lint!(

impl Rule for NoConditionalInTest {
fn run<'a>(&self, node: &oxc_semantic::AstNode<'a>, ctx: &LintContext<'a>) {
if matches!(
node.kind(),
match node.kind() {
AstKind::IfStatement(_)
| AstKind::SwitchStatement(_)
| AstKind::ConditionalExpression(_)
| AstKind::LogicalExpression(_)
) {
let is_if_statement_in_test = ctx.nodes().ancestors(node.id()).any(|node| {
let AstKind::CallExpression(call_expr) = node.kind() else { return false };
let vitest_node = PossibleJestNode { node, original: None };
| AstKind::SwitchStatement(_)
| AstKind::ConditionalExpression(_)
| AstKind::LogicalExpression(_) => {}
_ => return,
}

let is_if_statement_in_test = ctx.nodes().ancestors(node.id()).any(|node| {
let AstKind::CallExpression(call_expr) = node.kind() else { return false };
let vitest_node = PossibleJestNode { node, original: None };

is_type_of_jest_fn_call(
call_expr,
&vitest_node,
ctx,
&[JestFnKind::General(crate::utils::JestGeneralFnKind::Test)],
)
});
is_type_of_jest_fn_call(
call_expr,
&vitest_node,
ctx,
&[JestFnKind::General(crate::utils::JestGeneralFnKind::Test)],
)
});

if is_if_statement_in_test {
let span = match node.kind() {
AstKind::IfStatement(stmt) => stmt.span,
AstKind::SwitchStatement(stmt) => stmt.span,
AstKind::ConditionalExpression(expr) => expr.span,
AstKind::LogicalExpression(expr) => expr.span,
_ => unreachable!(),
};
if is_if_statement_in_test {
let span = match node.kind() {
AstKind::IfStatement(stmt) => stmt.span,
AstKind::SwitchStatement(stmt) => stmt.span,
AstKind::ConditionalExpression(expr) => expr.span,
AstKind::LogicalExpression(expr) => expr.span,
_ => unreachable!(),
};

ctx.diagnostic(no_conditional_in_test(span));
}
ctx.diagnostic(no_conditional_in_test(span));
}
}
}
Expand Down
Loading