eslint-plugin-no-floating-promise icon indicating copy to clipboard operation
eslint-plugin-no-floating-promise copied to clipboard

How to flag assignment of Promise to variable without await

Open vicatcu opened this issue 3 years ago • 2 comments

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?

vicatcu avatar Mar 11 '21 20:03 vicatcu