@@ -13,6 +13,7 @@ const messages = {
1313} ;
1414
1515const timerFunctions = new Set ( [ 'setTimeout' , 'setInterval' ] ) ;
16+ const globalObjects = new Set ( [ 'window' , 'globalThis' , 'global' , 'self' ] ) ;
1617
1718/**
1819Check 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