SonarLint 6.0.0.37696 returns “await” should only be used with promises (
javascript:S4123) for the case when I add await for a call of an async function for the following code:
const result = await _handleQueryException(targetItem.queryName, err.message);
SonarLint claims:
It is possible to use await on values which are not Promises, but it’s useless and misleading. The point of await is to pause execution until the Promise’s asynchronous code has run to completion. With anything other than a Promise, there’s nothing to wait for. This rule raises an issue when an awaited value is guaranteed not to be a Promise.
Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise.
Since _handleQueryException() is an async funtion:
const _handleQueryException = async function _handleQueryException(queryName, messageError) {…}
then I assume, that the MDN statement is valid here, while SonarLint raises a false-positive.
Please, check this case.
P.S. It’s my first report here, so please, let me know if something could be improved. BTW, should I post reports here or on Issues · SonarSource/SonarJS · GitHub ?
@pubmikeb thanks for quick responses!
This problem is reported by several users already but I fail to reproduce it, seems like some context matters here.
I had this issue on SonarQube 9.1, released on September 2021, since that time SonarQube has not been updated, so I believe, FP on S4123 still occurs on SonarQube 9.1
I’ve completely reinstalled SonarQube 9.1, ran the scan and of course I got this FP, since no change in SonarQube 9.1 has been performed since 9th Oct.