From 7ccb1c1a12233f3e1d633da8a9ac1679885694bc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 5 Apr 2017 19:11:48 -0700 Subject: [PATCH] tools: replace custom new-with-error rule Use no-restricted-syntax to implement the requirement that `Error` objects must be thrown with the `new` keyword. --- .eslintrc.yaml | 8 ++++--- tools/eslint-rules/new-with-error.js | 31 ---------------------------- 2 files changed, 5 insertions(+), 34 deletions(-) delete mode 100644 tools/eslint-rules/new-with-error.js diff --git a/.eslintrc.yaml b/.eslintrc.yaml index f4809c0fc913ae..07ef483c3f36b8 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -106,8 +106,11 @@ rules: message: "setTimeout() must be invoked with at least two arguments." }, { selector: "CallExpression[callee.name='setInterval'][arguments.length<2]", - message: "setInterval() must be invoked with at least 2 arguments" - }] + message: "setInterval() must be invoked with at least 2 arguments." + }, { + selector: "ThrowStatement > CallExpression[callee.name=/Error$/]", + message: "Use new keyword when throwing an Error." + }] no-tabs: 2 no-trailing-spaces: 2 one-var-declaration-per-line: 2 @@ -141,7 +144,6 @@ rules: align-multiline-assignment: 2 assert-fail-single-argument: 2 assert-throws-arguments: [2, { requireTwo: false }] - new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError] no-unescaped-regexp-dot: 2 # Global scoped method and vars diff --git a/tools/eslint-rules/new-with-error.js b/tools/eslint-rules/new-with-error.js deleted file mode 100644 index 655f34bf080956..00000000000000 --- a/tools/eslint-rules/new-with-error.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @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 -};