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

refactor(linter): jest prefer_strict_equal #5588

Merged
merged 1 commit into from
Sep 7, 2024
Merged
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
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