eslint-plugin-no-floating-promise
eslint-plugin-no-floating-promise copied to clipboard
How to flag assignment of Promise to variable without await
The following is an extraordinarily common pattern that this plugin seems to not register as a warning / error, but almost always is:
function WaitForIt() {
return new Promise(r, j) {
setTimeout(r, 1000);
}
}
async function WaitThenDo() {
const x = WaitForIt(); // this is a problem because it doesn't await
console.log('Doing it!');
}
The mere fact that the WaitForIt() call is bound to an assignment seems to prevent the plugin from noticing this as a problem? Is this a "bug" in this plugin, or is there a better / different plugin to handle this very common case?