aboutsummaryrefslogtreecommitdiff
path: root/deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js')
-rw-r--r--deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js b/deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js
new file mode 100644
index 00000000..655f34bf
--- /dev/null
+++ b/deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js
@@ -0,0 +1,31 @@
+/**
+ * @fileoverview Require `throw new Error()` rather than `throw Error()`
+ * @author Rich Trott
+ */
+'use strict';
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = function(context) {
+
+ var errorList = context.options.length !== 0 ? context.options : ['Error'];
+
+ return {
+ 'ThrowStatement': function(node) {
+ if (node.argument.type === 'CallExpression' &&
+ errorList.indexOf(node.argument.callee.name) !== -1) {
+ context.report(node, 'Use new keyword when throwing.');
+ }
+ }
+ };
+};
+
+module.exports.schema = {
+ 'type': 'array',
+ 'additionalItems': {
+ 'type': 'string'
+ },
+ 'uniqueItems': true
+};