Typescript '"void" should not be used' triggers wrongly

Hi guys,

currently SonarQube Developer Edition 8.5.1 is triggering a warning for the following code:

  const exampleFunction = () => { return new Promise(() => {});};
  void exampleFunction();

This is not the expected response as exampleFunction is a promise which you normally want to do something with.
But sometimes the promises isn’t interesting. So eslint is expecting a void in front of it to explicitly mark that the promise is not used.

The SonarQube example would like this:

  const exampleFunction = () => { return new Promise(() => {});};
  exampleFunction();

This code would lead to eslint telling you:

Promises must be handled appropriately or explicitly marked as ignored with the void operator. eslint@typescript-eslint/no-floating-promises

In my opinion eslint is right and SonarQube is wrong in this particular case.

Is the a possiblity to tailor the rule to exclude Promises?

Best
Ben

Any feedback? Do I need to open another tickets over our paid licenses?

Hi,

Thanks for the feedback (and sorry it took us so long to come back to you). Ticket is created to improve the rule Ignore promises in S3735 `void-use` · Issue #2629 · SonarSource/SonarJS · GitHub

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.