Skip to content
Permalink
Browse files
Fix: handle optional catch bindings in no-useless-catch (#11205)
This commit prevents a crash in the no-useless-catch rule
that occurs when optional catch bindings are used.
  • Loading branch information
cjihrig authored and platinumazure committed Dec 25, 2018
1 parent 0b81fc2 commit de79f1026b7035f0296d7876f1db64f225cca1b8
Showing with 11 additions and 0 deletions.
  1. +1 −0 lib/rules/no-useless-catch.js
  2. +10 −0 tests/lib/rules/no-useless-catch.js
@@ -27,6 +27,7 @@ module.exports = {
return {
CatchClause(node) {
if (
node.param &&
node.param.type === "Identifier" &&
node.body.body.length &&
node.body.body[0].type === "ThrowStatement" &&
@@ -103,6 +103,16 @@ ruleTester.run("no-useless-catch", rule, {
}
`,
parserOptions: { ecmaVersion: 8 }
},
{
code: `
try {
throw new Error('foo');
} catch {
throw new Error('foo');
}
`,
parserOptions: { ecmaVersion: 2019 }
}

],

0 comments on commit de79f10

Please sign in to comment.