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
This commit is contained in:
camc314 committed 2026-10-30 22:45:35 +00:00
1 parent e234dc853a
commit 987d5f14d1
1 file changed
+11 -1
@@ -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<Response>;
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![