The executor of a promise returns a value, which does not settle the promise

tx0/ts:promise-executor-returndefaultwarningbug

What it finds

new Promise((resolve) => { if (cached) return cached; ... }): the value returned from the function given to new Promise is ignored. The promise is settled only by calling resolve or reject, so a promise whose executor returns its result instead never settles.

Only executors with a block body that never mention their first parameter, the function that resolves the promise, are checked: then a returned value is the only result there is, and it is lost. return reject(e) is left alone, and so are return; and return void .... Promise must be the global one.

From the rule's source, promise_executor_return.rs.

Example from the rule's tests
function wait(cache: Map<string, number>, key: string) {  return new Promise((resolve, reject) => {    if (key === "") {      return reject(new Error("empty key"));    }    return cache.get(key);tx0 reports: returning from a promise executor does not resolve the promise  });}function load(cache: Map<string, number>, key: string) {  return new Promise((resolve) => {    if (cache.has(key)) {      return resolve(cache.get(key));    }    return setTimeout(() => resolve(0), 10);  });}function delay(ms: number) {  return new Promise((resolve) => setTimeout(resolve, ms));}
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:promise-executor-return" = "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:promise-executor-return] reason="..."

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