From 987d5f14d134e289284280a7c76a86ada30e358a Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Fri, 30 Oct 2026 22:45:35 +0000 Subject: [PATCH] fix(linter/unicorn/no-invalid-fetch-options): avoid treating unknown methods as GET (#28547) Treat unresolved `method` identifier bindings as unknown instead of retaining the default `GET` method. This avoids false positives for contextually typed destructured parameters and unannotated parameters, matching `eslint-plugin-unicorn`. Add six regression cases covering these bindings with both `fetch()` and `new Request()`. Existing diagnostics for known `GET` and `HEAD` methods remain unchanged. Fixes #27772 --- .../src/rules/unicorn/no_invalid_fetch_options.rs | 12 +++++++++++- 1 file changed, 11 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 e4ffc74f60..4f5f157bbb 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 @@ -239,7 +239,9 @@ fn is_invalid_fetch_options<'a>( } } } - _ => {} + _ => { + method_name = UNKNOWN_METHOD_NAME; + } } } _ => { @@ -337,6 +339,14 @@ fn test() { (r#"new Request("/url", { method: (options).method, body: "some body" });"#), r#"enum M { A = "\uD800" } fetch(u, {method: M.A, body: "x"})"#, r#"enum M { A = "\uD800", B = "GET" } fetch(u, {method: M.A, body: "x"})"#, + r#"type Handler = (input: { body?: string; method: string }) => Promise; + export const contextual: Handler = ({ body, method }) => fetch("/", { body, method });"#, + r#"type Handler = (input: { body?: string; method: string }) => Request; + export const contextual: Handler = ({ body, method }) => new Request("/", { body, method });"#, + r#"function request({ body, method }) { return fetch("/", { body, method }); }"#, + r#"function request({ body, method }) { return new Request("/", { body, method }); }"#, + r#"function request(method) { return fetch("/", { method, body: "foo=bar" }); }"#, + r#"function request(method) { return new Request("/", { method, body: "foo=bar" }); }"#, ]; let fail = vec![