I am using SonarQube for IDE with the latest versions of VS Code and the SonarQube extension. Not in connected mode. I have the following code:
pool
.query(`SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';`)
.then((res) => {
console.log(res);
})
.catch((err: unknown) => {
console.log(err);
});
The following rule is getting triggered:
However, the description of rule typescript:S7785 is not related to my code at all. The description centers around this idea:
When you wrap async operations in immediately invoked function expressions (IIFEs) or create async functions just to call them immediately, you add unnecessary boilerplate code.
There is only one example, and it shows an IIFE, with a try-catch block inside it:
My code does not involve any IIFE. I am just calling pool.query(), which returns a promise, and I could either use a promise chain or a top-level await. I am not wrapping it in an extra function in either case.
I am not sure if this is a false positive, or whether the description of the rule needs to be enhanced to explain that promise chains are generally not preferred over top-level await. If it’s the latter, note that it conflicts with this Node.js ESLint rule (it’s not one of the recommended ones): eslint-plugin-n/docs/rules/no-top-level-await.md at c1b1b8427e94f751b4e4ffa9d77cbe2d6b4412c9 · eslint-community/eslint-plugin-n · GitHub

