useAwait
Summary
Section titled “Summary”- Rule available since:
v1.4.0 - Diagnostic Category:
lint/suspicious/useAwait - 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.
- Sources:
- Same as
require-await - Same as
@typescript-eslint/require-await
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "useAwait": "error" } } }}Description
Section titled “Description”Ensure async functions utilize await.
This rule reports async functions that lack an await expression or another
operation that requires async semantics. 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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”async function fetchData() {// Missing `await` for the promise returned by `fetch` return fetch('/data');}code-block.js:1:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This async function lacks an await expression.
> 1 │ async function fetchData() {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ // Missing `await` for the promise returned by `fetch`
> 3 │ return fetch(‘/data’);
> 4 │ }
│ ^
5 │
ℹ Remove this async modifier, or add an await expression in the function.
> 1 │ async function fetchData() {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ // Missing `await` for the promise returned by `fetch`
> 3 │ return fetch(‘/data’);
> 4 │ }
│ ^
5 │
ℹ Async functions without await expressions may not need to be declared async.
async function fetchData() { const response = await fetch('/data'); const data = await response.json(); return data;}
// This rule does not warn about non-async functionsfunction processData() { return compute(data);}
// Nor does it warn about empty `async` functionsasync function noop() { }
// Async generators that use `yield*` with an async iterableasync function* delegateToAsyncIterable() { yield* otherAsyncIterable();}
// `await using` awaits asynchronous resource disposalasync function consumeResource() { await using resource = acquire(); consume(resource);}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.