An async function returns Promise.resolve or Promise.reject of a value

tx0/ts:promise-wrap-in-asyncstrictwarningstyle

What it finds

An async function wraps what it returns in a promise and turns what it throws into a rejection, so return Promise.resolve(value) and return Promise.reject(error) in one wrap twice: return value and throw error say the same.

Reported are return statements of async functions whose value is a call of Promise.resolve or Promise.reject on the global Promise.

From the rule's source, promise_wrap_in_async.rs.

Example from the rule's tests
export async function load(ok: boolean) {  if (!ok) {    return Promise.reject(new Error("no"));tx0 reports: throw the error  }  return Promise.resolve(1);tx0 reports: return the value}export function plain() {  return Promise.resolve(2);}
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:promise-wrap-in-async" = "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:promise-wrap-in-async] reason="..."

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