mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 22:02:33 +00:00

Add linting rule requiring `throw new Error()` over `throw Error()`. PR-URL: https://github.com/nodejs/node/pull/3714 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
37 lines
845 B
JavaScript
37 lines
845 B
JavaScript
/**
|
|
* @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',
|
|
'items': [
|
|
{
|
|
'enum': [0, 1, 2]
|
|
}
|
|
],
|
|
'additionalItems': {
|
|
'type': 'string'
|
|
},
|
|
'uniqueItems': true
|
|
};
|