diff options
Diffstat (limited to 'tools/eslint/lib/rules/no-throw-literal.js')
-rw-r--r-- | tools/eslint/lib/rules/no-throw-literal.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-throw-literal.js b/tools/eslint/lib/rules/no-throw-literal.js new file mode 100644 index 0000000000..d02e7786b6 --- /dev/null +++ b/tools/eslint/lib/rules/no-throw-literal.js @@ -0,0 +1,31 @@ +/** + * @fileoverview Rule to restrict what can be thrown as an exception. + * @author Dieter Oberkofler + * @copyright 2015 Dieter Oberkofler. All rights reserved. + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = function(context) { + + return { + + "ThrowStatement": function(node) { + + if (node.argument.type === "Literal") { + context.report(node, "Do not throw a literal."); + } else if (node.argument.type === "Identifier") { + if (node.argument.name === "undefined") { + context.report(node, "Do not throw undefined."); + } + } + + } + + }; + +}; |