mirror of https://github.com/lukechilds/node.git
Browse Source
Use no-restricted-syntax to implement the requirement that `Error` objects must be thrown with the `new` keyword. PR-URL: https://github.com/nodejs/node/pull/12249 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>v6.x
committed by
Myles Borins
2 changed files with 5 additions and 34 deletions
@ -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 |
|
||||
}; |
|
Loading…
Reference in new issue