Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven committed Aug 10, 2024
1 parent 7c730de commit a63ec37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare_oxc_lint!(
/// })
/// ```
NoReturnInFinally,
correctness,
nursery,
);

impl Rule for NoReturnInFinally {
Expand Down
12 changes: 5 additions & 7 deletions crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ impl Rule for PreferAwaitToThen {
return;
};

let Some(prop_name) = is_promise(call_expr) else {
return;
};

// Await statements cannot be added to the top level scope
if ctx.scopes().get_flags(node.scope_id()).is_top() {
if is_promise(call_expr).is_none() {
return;
}

Expand Down Expand Up @@ -73,7 +68,9 @@ fn test() {
"a = async () => {
try { await something() } catch (error) { somethingElse() }
}",
"something().then(async () => await somethingElse())",
// <https://github.com/tc39/proposal-top-level-await>
// Top level await is allowed now, so comment this out
// "something().then(async () => await somethingElse())",
"function foo() { hey.somethingElse(x => {}) }",
"const isThenable = (obj) => {
return obj && typeof obj.then === 'function';
Expand All @@ -90,6 +87,7 @@ fn test() {
"async function a() { hey.then(function() { }).then(function() { }) }",
"function foo() { hey.catch(x => {}) }",
"function foo() { hey.finally(x => {}) }",
"something().then(async () => await somethingElse())",
];

Tester::new(PreferAwaitToThen::NAME, pass, fail).test_and_snapshot();
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/snapshots/prefer_await_to_then.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ source: crates/oxc_linter/src/tester.rs
1function foo() { hey.finally(x => {}) }
· ────────────────────
╰────

eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
╭─[prefer_await_to_then.tsx:1:1]
1something().then(async () => await somethingElse())
· ───────────────────────────────────────────────────
╰────

0 comments on commit a63ec37

Please sign in to comment.