refactor: Remove usless catch blocks, and add a linting rule to prevent them (no-changelog) (#12730)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-01-20 18:20:04 +01:00
committed by GitHub
parent 4ee4552b0e
commit 202da76380
17 changed files with 220 additions and 242 deletions

View File

@@ -51,3 +51,33 @@ ruleTester.run('no-json-parse-json-stringify', rules['no-json-parse-json-stringi
},
],
});
ruleTester.run('no-useless-catch-throw', rules['no-useless-catch-throw'], {
valid: [
{
code: 'try { foo(); } catch (e) { console.error(e); }',
},
{
code: 'try { foo(); } catch (e) { throw new Error("Custom error"); }',
},
],
invalid: [
{
code: `
try {
// Some comment
if (foo) {
bar();
}
} catch (e) {
throw e;
}`,
errors: [{ messageId: 'noUselessCatchThrow' }],
output: `
// Some comment
if (foo) {
bar();
}`,
},
],
});