Skip to content

Commit ada4e84

Browse files
committed
fix(linter/prefer-await-to-then): false positive with Promise call as return arg (#13189)
fixes #13167
1 parent d676e04 commit ada4e84

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ impl Rule for PreferAwaitToThen {
8282
return;
8383
}
8484

85+
if matches!(ctx.nodes().parent_kind(node.id()), AstKind::ReturnStatement(_)) {
86+
return;
87+
}
88+
8589
if !self.strict {
8690
// Already inside a yield or await
8791
if ctx.nodes().ancestors(node.id()).any(is_inside_yield_or_await) {
@@ -134,6 +138,9 @@ fn test() {
134138
Some(serde_json::json!({ "strict": false })),
135139
),
136140
("const { promise, resolve } = Promise.withResolvers()", None),
141+
("function x () { return Promise.all() } ", None),
142+
("function foo() { return hey.then(x => x) }", None),
143+
("async function foo() { return thing().then(x => x) }", None),
137144
];
138145

139146
let fail = vec![

0 commit comments

Comments
 (0)