async Promise executor
This is how the comment reads inline, under the flagged line.
Why it matters
Errors thrown inside an async executor are lost; the outer promise hangs forever.
What to do
Drop the new Promise wrapper and write an async function.
Examples
return new Promise(async (resolve) => { resolve(await load()); });return load();
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
return new Promise(async (resolve) => resolve(1));
Left alone
return new Promise((resolve) => resolve(1));
Research
`async` callbacks in `forEach`, and `async` Promise executors. The returned promises are dropped, so the caller moves on early and rejections escape.
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"async-promise-executor"
],
"severity": {
"async-promise-executor": "low"
}
}
}
asyncfunction as a Promise executor. If it throws, the promise never settles.