Skip to content

Commit

Permalink
refactor(linter): jest prefer_strict_equal (#5588)
Browse files Browse the repository at this point in the history
simplify code
  • Loading branch information
IWANABETHATGUY committed Sep 7, 2024
1 parent 40d0149 commit 2661d8b
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
Expand Down Expand Up @@ -47,22 +46,12 @@ impl Rule for PreferStrictEqual {
}

impl PreferStrictEqual {
fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) {
let node = possible_jest_node.node;
let AstKind::CallExpression(call_expr) = node.kind() else {
return;
};
let Some(parse_jest_expect_fn_call) =
parse_expect_jest_fn_call(call_expr, possible_jest_node, ctx)
else {
return;
};
let Some(matcher) = parse_jest_expect_fn_call.matcher() else {
return;
};
let Some(matcher_name) = matcher.name() else {
return;
};
fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) -> Option<()> {
let call_expr = possible_jest_node.node.kind().as_call_expression()?;
let parse_jest_expect_fn_call =
parse_expect_jest_fn_call(call_expr, possible_jest_node, ctx)?;
let matcher = parse_jest_expect_fn_call.matcher()?;
let matcher_name = matcher.name()?;

if matcher_name.eq("toEqual") {
ctx.diagnostic_with_fix(use_to_strict_equal(matcher.span), |fixer| {
Expand All @@ -75,6 +64,7 @@ impl PreferStrictEqual {
fixer.replace(matcher.span, replacement)
});
}
None
}
}

Expand Down

0 comments on commit 2661d8b

Please sign in to comment.