tools: replace custom ESLint timers rule
ESLint 3.19.0 allows the specification of selectors that represent disallowed syntax. Replace our custom rule for timer arguments with a pair of `no-restricted-syntax` option objects. PR-URL: https://github.com/nodejs/node/pull/12162 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
316665235c
commit
f637703b86
@ -101,6 +101,13 @@ rules:
|
|||||||
new-parens: 2
|
new-parens: 2
|
||||||
no-mixed-spaces-and-tabs: 2
|
no-mixed-spaces-and-tabs: 2
|
||||||
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
|
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
|
||||||
|
no-restricted-syntax: [2, {
|
||||||
|
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
|
||||||
|
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"
|
||||||
|
}]
|
||||||
no-tabs: 2
|
no-tabs: 2
|
||||||
no-trailing-spaces: 2
|
no-trailing-spaces: 2
|
||||||
one-var-declaration-per-line: 2
|
one-var-declaration-per-line: 2
|
||||||
@ -135,7 +142,6 @@ rules:
|
|||||||
assert-fail-single-argument: 2
|
assert-fail-single-argument: 2
|
||||||
assert-throws-arguments: [2, { requireTwo: false }]
|
assert-throws-arguments: [2, { requireTwo: false }]
|
||||||
new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError]
|
new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError]
|
||||||
timer-arguments: 2
|
|
||||||
no-unescaped-regexp-dot: 2
|
no-unescaped-regexp-dot: 2
|
||||||
|
|
||||||
# Global scoped method and vars
|
# Global scoped method and vars
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Require at least two arguments when calling setTimeout() or
|
|
||||||
* setInterval().
|
|
||||||
* @author Rich Trott
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
function isTimer(name) {
|
|
||||||
return ['setTimeout', 'setInterval'].includes(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
return {
|
|
||||||
'CallExpression': function(node) {
|
|
||||||
const name = node.callee.name;
|
|
||||||
if (isTimer(name) && node.arguments.length < 2) {
|
|
||||||
context.report(node, `${name} must have at least 2 arguments`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user