src/content/docs/linter/rules/use-await.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.4.0` - Diagnostic Category: [`lint/suspicious/useAwait`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`require-await`](https://eslint.org/docs/latest/rules/require-await) - Same as [`@typescript-eslint/require-await`](https://typescript-eslint.io/rules/require-await){
"linter": {
"rules": {
"suspicious": {
"useAwait": "error"
}
}
}
}
Ensure async functions utilize await.
This rule reports async functions that lack an await expression. As async
functions return a promise, the use of await is often necessary to capture the
resolved value and handle the asynchronous operation appropriately. Without await,
the function operates synchronously and might not leverage the advantages of async
functions.
async function fetchData() {
// Missing `await` for the promise returned by `fetch`
return fetch('/data');
}
async function fetchData() {
const response = await fetch('/data');
const data = await response.json();
return data;
}
// This rule does not warn about non-async functions
function processData() {
return compute(data);
}
// Nor does it warn about empty `async` functions
async function noop() { }
// Async generators that use `yield*` with an async iterable
async function* delegateToAsyncIterable() {
yield* otherAsyncIterable();
}