mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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. 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>
This commit is contained in:
1 parent
19d95519c7
commit
b2a08fb130
2 files changed
+5
-34
No files matched your search
+5
-3
@@ -109,8 +109,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
|
||||
operator-linebreak: [2, after, {overrides: {'?': ignore, ':': ignore}}]
|
||||
@@ -142,7 +145,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-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
|
||||
|
||||
# Global scoped method and vars
|
||||
|
||||
@@ -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
|
||||
};
|
||||
Reference in new issue
Block a user