From 1c08879390b9db8ac97bf005a41aa4dfb09861d2 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Sun, 7 Dec 2025 12:07:26 +0000 Subject: [PATCH] fix(linter): fix false positive in no-invalid-fetch-options for conditional expressions (#16570) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the method property is a conditional expression (e.g., `logic ? "PATCH" : "POST"`), the rule should not report an error since the method cannot be statically determined. Previously, unrecognized expression types would fall through to a no-op case, leaving the method_name at its default value of "GET", causing false positives. Closes #16569 🤖 generated with help from Claude Opus 4.5 --- .../src/rules/unicorn/no_invalid_fetch_options.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 e8890bdb73447..a96c5c74d9297 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 @@ -222,7 +222,9 @@ fn is_invalid_fetch_options<'a>( _ => {} } } - _ => {} + _ => { + method_name = UNKNOWN_METHOD_NAME; + } } } } @@ -296,6 +298,9 @@ fn test() { body: "", });"#, ("const response = await fetch('', { method, headers, body, });"), + (r#"fetch("/url", { method: logic ? "PATCH" : "POST", body: "some body" });"#), + (r#"new Request("/url", { method: logic ? "PATCH" : "POST", body: "some body" });"#), + (r#"fetch("/url", { method: getMethod(), body: "some body" });"#), ]; let fail = vec![