From 78261d63c0df2b31374d04c4576fceb3b9e5f336 Mon Sep 17 00:00:00 2001 From: camchenry <1514176+camchenry@users.noreply.github.com> Date: Thu, 9 Oct 2025 05:39:12 +0000 Subject: [PATCH] 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. --- .../src/generated/rule_runner_impls.rs | 3 ++- .../rules/unicorn/no_invalid_fetch_options.rs | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/oxc_linter/src/generated/rule_runner_impls.rs b/crates/oxc_linter/src/generated/rule_runner_impls.rs index 70a5e8bc9f523..9bec27f686772 100644 --- a/crates/oxc_linter/src/generated/rule_runner_impls.rs +++ b/crates/oxc_linter/src/generated/rule_runner_impls.rs @@ -2416,7 +2416,8 @@ impl RuleRunner for crate::rules::unicorn::no_instanceof_builtins::NoInstanceofB } impl RuleRunner for crate::rules::unicorn::no_invalid_fetch_options::NoInvalidFetchOptions { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::NewExpression])); } impl RuleRunner diff --git a/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs b/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs index 732afaa24fe9a..dc3d4f05fa7d0 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs @@ -59,29 +59,30 @@ declare_oxc_lint!( impl Rule for NoInvalidFetchOptions { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - let arg = match node.kind() { + match node.kind() { AstKind::CallExpression(call_expr) => { if !call_expr.callee.is_specific_id("fetch") || call_expr.arguments.len() < 2 { return; } - &call_expr.arguments[1] + if let Argument::ObjectExpression(expr) = &call_expr.arguments[1] + && let Some((method_name, body_span)) = is_invalid_fetch_options(expr, ctx) + { + ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name)); + } } AstKind::NewExpression(new_expr) => { if !is_new_expression(new_expr, &["Request"], Some(2), None) { return; } - &new_expr.arguments[1] + if let Argument::ObjectExpression(expr) = &new_expr.arguments[1] + && let Some((method_name, body_span)) = is_invalid_fetch_options(expr, ctx) + { + ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name)); + } } - _ => return, - }; - - let Argument::ObjectExpression(expr) = arg else { return }; - let result = is_invalid_fetch_options(expr, ctx); - - if let Some((method_name, body_span)) = result { - ctx.diagnostic(no_invalid_fetch_options_diagnostic(body_span, &method_name)); + _ => {} } } }