Skip to content

Commit d47e3b0

Browse files
committed
linter: ignore Promise static methods in prefer-await-to-then
1 parent 4ef93ea commit d47e3b0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ impl Rule for PreferAwaitToThen {
8282
return;
8383
};
8484

85-
if is_promise_with_context(call_expr, ctx).is_none_or(|v| v == "withResolvers") {
85+
let Some(method_name) = is_promise_with_context(call_expr, ctx) else {
86+
return;
87+
};
88+
89+
if !matches!(method_name.as_str(), "then" | "catch" | "finally") {
8690
return;
8791
}
8892

@@ -114,6 +118,12 @@ fn test() {
114118
("async function hi() { await thing() }", None),
115119
("async function hi() { await thing().then() }", None),
116120
("async function hi() { await thing().catch() }", None),
121+
("const x = Promise.resolve(42)", None),
122+
("const x = Promise.reject(error)", None),
123+
("const x = Promise.all(values)", None),
124+
("const x = Promise.allSettled(values)", None),
125+
("const x = Promise.any(values)", None),
126+
("const x = Promise.race(values)", None),
117127
("a = async () => (await something())", None),
118128
(
119129
"a = async () => {

0 commit comments

Comments
 (0)