sonarjs/no-try-promise
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-try-promise": "error",
},
},
];Promise rejections should not be caught by "try" blocks
function runPromise() {
return Promise.reject("rejection reason");
}
function foo() {
try { // Noncompliant, the catch clause of the 'try' will not be executed for the code inside promise
runPromise();
} catch (e) {
console.log("Failed to run promise", e);
}
}function foo() {
runPromise().catch(e => console.log("Failed to run promise", e));
}
// or
async function foo() {
try {
await runPromise();
} catch (e) {
console.log("Failed to run promise", e);
}
}Examples from the ESLint documentation.
sonarjs/no-try-promise
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-try-promise": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
"undefined" should not be passed as the value of optional parameters
HTML "<table>" should not be used for layout purposes
Multiline blocks should be enclosed in curly braces
"if" statements should be preferred over "switch" when simpler
JSX list components keys should match up between renders