oxc/no-async-await
Disallow async functions
Some projects avoid async functions. They target engines that don't have them and don't want the helper code a compiler adds, or they use promise chains or callbacks everywhere.
The rule reports the async keyword on function declarations, function expressions, arrow functions and methods. Since await needs an async function around it, that covers await too.
Two things aren't reported: await at the top level of a module, and an unnamed function that's the value of an object property, as in { save: async function () {} }.
Configure#
Off by default. To turn it on:
[lint.rules]
"oxc/no-async-await" = "error" # or "warn"Examples#
asyncasync is not allowed function loadUser(id) {
const response = await fetch(`/users/${id}`);
return response.json();
}
const refresh = asyncasync is not allowed () => {
await loadUser(current.id);
};
class Store {
asyncasync is not allowed save() {}
}function loadUser(id) {
return fetch(`/users/${id}`).then((response) => response.json());
}
const refresh = () => loadUser(current.id);Also not reported, even though they use async or await:
const config = await loadConfig();
const handlers = { save: async function () {} };When not to use it#
async and await work in Bun, Node.js and every current browser. Only turn this rule on if your project has a reason to avoid them.