feat(no-invalid-fetch-options): add no-invalid-fetch-options rule - #1530
feat(no-invalid-fetch-options): add no-invalid-fetch-options rule#1530bartlomieju wants to merge 2 commits into
no-invalid-fetch-options rule#1530Conversation
|
Verdict: LGTM — correct and conservative. Recommend merge after the RECOMMENDED sign-off you flagged + rebase. Not auto-merging (new rule). Flags a Correctness — verified
Minor / faithful edges
Perf: trivial (per call/new, linear over object props). Housekeeping: No code changes requested — the conservative design and edge handling are sound. Just tagging + rebase. |
Ports the oxlint
unicorn/no-invalid-fetch-optionsrule to deno_lint as anative Rust rule.
The rule flags a
bodypassed tofetch(url, { ... })ornew Request(url, { ... })when themethodisGETorHEAD(case-insensitive), since a body is not allowed for those methods and results
in a
TypeErrorat runtime. An absentmethoddefaults toGET, so a bodywith no method is also flagged. A
bodyofnullorundefinedis treated asabsent and not reported. Method values are read from string and single-element
template literals; values that cannot be read statically (variable references,
member expressions, enums, type annotations, conditionals, call results) are
treated as unknown and not flagged.
Both
fetch(...)calls andnew Request(...)are covered, matching oxc.Reference:
https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs
This port intentionally only inspects the
methodvalue when it is written asan inline string or single-element template literal. It does not resolve method
values that come from another statement, a TypeScript enum member, or a typed
function parameter. As a result, six of oxc's
failfixtures are deliberatelynot reproduced here (they would require cross-statement symbol resolution, enum
member resolution, or parameter type-annotation analysis):
const method = "head"; new Request(url, {method, body: "foo=bar"})const method = "head"; fetch(url, {method, body: "foo=bar"})const method = `head`; fetch(url, {method, body: "foo=bar"})function foo(method: "HEAD" | "GET") { return new Request(url, {method, body: ""}); }enum Method { Get = "GET" } ... fetch("/", { method: Method.Get, body: "" })enum Method { Foo = "GET" } ... fetch("/", { method: Method.Foo, body: "" })Because the rule treats an unresolved method as unknown (and therefore safe),
every one of oxc's
passfixtures is reproduced verbatim and still passes —including the variable-, enum-, parameter-,
as const-, andmember-expression-typed method cases. A less-capable rule simply flags fewer
things, so no genuine valid case regresses.
Tagged RECOMMENDED (on by default) — flagging for maintainer sign-off.