Skip to content

Commit f96fb53

Browse files
committed
no-restricted-globals
1 parent 1ccb4d2 commit f96fb53

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@
9292
"no-new-wrappers": "error",
9393
"no-redeclare": "off",
9494
"no-return-await": "error",
95-
"no-restricted-globals": "off",
95+
"no-restricted-globals": ["error",
96+
{ "name": "setTimeout" },
97+
{ "name": "setInterval" },
98+
{ "name": "clearTimeout" },
99+
{ "name": "setImmediate" },
100+
{ "name": "clearImmediate" }
101+
],
96102
"no-sequences": "off",
97103
"no-shadow": "off",
98104
"no-sparse-arrays": "error",

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,19 +769,22 @@ namespace Harness.LanguageService {
769769
}
770770

771771
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any {
772-
// tslint:disable-next-line:ban
772+
// eslint-disable-next-line no-restricted-globals
773773
return setTimeout(callback, ms, args);
774774
}
775775

776776
clearTimeout(timeoutId: any): void {
777+
// eslint-disable-next-line no-restricted-globals
777778
clearTimeout(timeoutId);
778779
}
779780

780781
setImmediate(callback: (...args: any[]) => void, _ms: number, ...args: any[]): any {
782+
// eslint-disable-next-line no-restricted-globals
781783
return setImmediate(callback, args);
782784
}
783785

784786
clearImmediate(timeoutId: any): void {
787+
// eslint-disable-next-line no-restricted-globals
785788
clearImmediate(timeoutId);
786789
}
787790

src/testRunner/parallel/host.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,15 @@ namespace Harness.Parallel.Host {
297297
return process.exit(2);
298298
}
299299
case "timeout": {
300-
if (worker.timer) clearTimeout(worker.timer);
300+
if (worker.timer) {
301+
// eslint-disable-next-line no-restricted-globals
302+
clearTimeout(worker.timer);
303+
}
301304
if (data.payload.duration === "reset") {
302305
worker.timer = undefined;
303306
}
304307
else {
305-
// tslint:disable-next-line:ban
308+
// eslint-disable-next-line no-restricted-globals
306309
worker.timer = setTimeout(killChild, data.payload.duration, data.payload);
307310
}
308311
break;
@@ -624,7 +627,7 @@ namespace Harness.Parallel.Host {
624627
shimNoopTestInterface(global);
625628
}
626629

627-
// tslint:disable-next-line:ban
630+
// eslint-disable-next-line no-restricted-globals
628631
setTimeout(() => startDelayed(perfData, totalCost), 0); // Do real startup on next tick, so all unit tests have been collected
629632
}
630633
}

src/tsserver/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ namespace ts.server {
482482
// so we defer until the next tick.
483483
//
484484
// Construction should finish before the next tick fires, so we do not need to do this recursively.
485+
// eslint-disable-next-line no-restricted-globals
485486
setImmediate(() => this.event(body, eventName));
486487
}
487488
};
@@ -698,7 +699,7 @@ namespace ts.server {
698699
// stat due to inconsistencies of fs.watch
699700
// and efficiency of stat on modern filesystems
700701
function startWatchTimer() {
701-
// tslint:disable-next-line:ban
702+
// eslint-disable-next-line no-restricted-globals
702703
setInterval(() => {
703704
let count = 0;
704705
let nextToCheck = nextFileToCheck;
@@ -881,10 +882,13 @@ namespace ts.server {
881882
};
882883
};
883884

885+
/* eslint-disable no-restricted-globals */
884886
sys.setTimeout = setTimeout;
885887
sys.clearTimeout = clearTimeout;
886888
sys.setImmediate = setImmediate;
887889
sys.clearImmediate = clearImmediate;
890+
/* eslint-enable no-restricted-globals */
891+
888892
if (typeof global !== "undefined" && global.gc) {
889893
sys.gc = () => global.gc();
890894
}

0 commit comments

Comments
 (0)