An async function contains no await

tx0/ts:async-without-awaitstrictwarningsmell

What it finds

async function total(items) { return sum(items); }: a function marked async that never awaits anything runs to its end at once and wraps its result in a promise. The marker suggests waiting that does not happen, and callers have to await for no reason.

Functions with an empty body, as stubs and no-op implementations of an async interface are, are left alone. Some interfaces require a promise, which is why the rule is strict.

From the rule's source, async_without_await.rs.

Example from the rule's tests
async function total(items: number[]) {tx0 reports: this async function never awaits  return items.length;}async function load(id: string) {  return await fetch(id);}async function stub() {}const quick = async (x: number) => x;tx0 reports: this async function never awaitsconst awaited = async (x: Promise<number>) => await x;class Store {  async read() {tx0 reports: this async function never awaits    const inner = async () => {      await fetch("x");    };    return inner;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:async-without-await" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:async-without-await] reason="..."

tx0 explain tx0/ts:async-without-await shows the same in the terminal. Found a false positive? Report it.