Skip to content

Commit 78261d6

Browse files
committed
perf(linter): refactor no-invalid-fetch-options to be more easily analyzed (#14458)
Updating the code style here so that the linter codegen can more easily analyze this rule's node types. +1% perf gain on the radix UI benchmark file.
1 parent 8c3be35 commit 78261d6

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,8 @@ impl RuleRunner for crate::rules::unicorn::no_instanceof_builtins::NoInstanceofB
24162416
}
24172417

24182418
impl RuleRunner for crate::rules::unicorn::no_invalid_fetch_options::NoInvalidFetchOptions {
2419-
const NODE_TYPES: Option<&AstTypesBitset> = None;
2419+
const NODE_TYPES: Option<&AstTypesBitset> =
2420+
Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::NewExpression]));
24202421
}
24212422

24222423
impl RuleRunner

crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,30 @@ declare_oxc_lint!(
5959

6060
impl Rule for NoInvalidFetchOptions {
6161
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
62-
let arg = match node.kind() {
62+
match node.kind() {
6363
AstKind::CallExpression(call_expr) => {
6464
if !call_expr.callee.is_specific_id("fetch") || call_expr.arguments.len() < 2 {
6565
return;
6666
}
6767

68-
&call_expr.arguments[1]
68+
if let Argument::ObjectExpression(expr) = &call_expr.arguments[1]
69+
&& let Some((method_name, body_span)) = is_invalid_fetch_options(expr, ctx)
70+
{
71+
ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name));
72+
}
6973
}
7074
AstKind::NewExpression(new_expr) => {
7175
if !is_new_expression(new_expr, &["Request"], Some(2), None) {
7276
return;
7377
}
7478

75-
&new_expr.arguments[1]
79+
if let Argument::ObjectExpression(expr) = &new_expr.arguments[1]
80+
&& let Some((method_name, body_span)) = is_invalid_fetch_options(expr, ctx)
81+
{
82+
ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name));
83+
}
7684
}
77-
_ => return,
78-
};
79-
80-
let Argument::ObjectExpression(expr) = arg else { return };
81-
let result = is_invalid_fetch_options(expr, ctx);
82-
83-
if let Some((method_name, body_span)) = result {
84-
ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name));
85+
_ => {}
8586
}
8687
}
8788
}

0 commit comments

Comments
 (0)