The executor of a new promise is an async function

tx0/ts:async-promise-executordefaultwarningbug

What it finds

new Promise(async (resolve, reject) => ...): an exception thrown in an async executor rejects the promise the executor returns, which nobody sees, instead of the one being constructed, which then never settles. An async executor also suggests the promise is not needed, since the async function already is one.

Only the global Promise is checked. An executor whose whole body is a try statement with a catch clause handles its exceptions itself and is left alone.

From the rule's source, async_promise_executor.rs.

Example from the rule's tests
function load(url: string) {  return new Promise(async (resolve, reject) => {tx0 reports: the executor of a promise should not be async    resolve(await fetch(url));  });} function guarded(url: string) {  return new Promise(async (resolve, reject) => {    try {      resolve(await fetch(url));    } catch (error) {      reject(error);    }  });} function plain(url: string) {  return new Promise(resolve => resolve(fetch(url)));}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:async-promise-executor" = "off"

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-promise-executor] reason="..."

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