1/** 2 * @fileoverview Require `throw new Error()` rather than `throw Error()` 3 * @author Rich Trott 4 */ 5'use strict'; 6 7//------------------------------------------------------------------------------ 8// Rule Definition 9//------------------------------------------------------------------------------ 10 11module.exports = function(context) { 12 13 var errorList = context.options.length !== 0 ? context.options : ['Error']; 14 15 return { 16 'ThrowStatement': function(node) { 17 if (node.argument.type === 'CallExpression' && 18 errorList.indexOf(node.argument.callee.name) !== -1) { 19 context.report(node, 'Use new keyword when throwing.'); 20 } 21 } 22 }; 23}; 24 25module.exports.schema = { 26 'type': 'array', 27 'additionalItems': { 28 'type': 'string' 29 }, 30 'uniqueItems': true 31}; 32