Skip to content

Commit a99744d

Browse files
committed
explicit-timer-delay: restrict global matcher and skip unsafe fixer
1 parent 704256a commit a99744d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

rules/explicit-timer-delay.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const messages = {
1313
};
1414

1515
const timerFunctions = new Set(['setTimeout', 'setInterval']);
16+
const globalObjects = new Set(['window', 'globalThis', 'global', 'self']);
1617

1718
/**
1819
Check if a call expression is a timer function call.
@@ -41,6 +42,7 @@ const checkTimerCall = (node, sourceCode) => {
4142

4243
if (
4344
object.type === 'Identifier'
45+
&& globalObjects.has(object.name)
4446
&& sourceCode.isGlobalReference(object)
4547
) {
4648
return {isTimer: true, name: callee.property.name};
@@ -105,17 +107,22 @@ const create = context => {
105107
const delayArgument = arguments_[1];
106108

107109
if (isZeroDelay(delayArgument)) {
108-
return {
110+
const problem = {
109111
node: delayArgument,
110112
messageId: MESSAGE_ID_REDUNDANT_DELAY,
111113
data: {name},
112-
fix(fixer) {
114+
};
115+
116+
if (arguments_.length === 2) {
117+
problem.fix = function (fixer) {
113118
const [firstArgument] = arguments_;
114119
const [, firstArgumentEnd] = getParenthesizedRange(firstArgument, context);
115120
const [, delayArgumentEnd] = getParenthesizedRange(delayArgument, context);
116121
return fixer.removeRange([firstArgumentEnd, delayArgumentEnd]);
117-
},
118-
};
122+
};
123+
}
124+
125+
return problem;
119126
}
120127
}
121128
});

0 commit comments

Comments
 (0)