diff options
Diffstat (limited to 'tools/node_modules/eslint/lib/rules/no-useless-catch.js')
-rw-r--r-- | tools/node_modules/eslint/lib/rules/no-useless-catch.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/lib/rules/no-useless-catch.js b/tools/node_modules/eslint/lib/rules/no-useless-catch.js new file mode 100644 index 0000000000..3211ed2c73 --- /dev/null +++ b/tools/node_modules/eslint/lib/rules/no-useless-catch.js @@ -0,0 +1,51 @@ +/** + * @fileoverview Reports useless `catch` clauses that just rethrow their error. + * @author Teddy Katz + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + type: "suggestion", + + docs: { + description: "disallow unnecessary `catch` clauses", + category: "Best Practices", + recommended: false, + url: "https://eslint.org/docs/rules/no-useless-catch" + }, + + schema: [] + }, + + create(context) { + return { + CatchClause(node) { + if ( + node.param.type === "Identifier" && + node.body.body.length && + node.body.body[0].type === "ThrowStatement" && + node.body.body[0].argument.type === "Identifier" && + node.body.body[0].argument.name === node.param.name + ) { + if (node.parent.finalizer) { + context.report({ + node, + message: "Unnecessary catch clause." + }); + } else { + context.report({ + node: node.parent, + message: "Unnecessary try/catch wrapper." + }); + } + } + } + }; + } +}; |