Skip to content

Enable no-eval rule #29860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/harness/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace evaluator {
}

const evaluateText = `(function (module, exports, require, __dirname, __filename, ${globalNames.join(", ")}) { ${output.text} })`;
// tslint:disable-next-line:no-eval
const evaluateThunk = eval(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
const module: { exports: any; } = { exports: {} };
evaluateThunk.call(globals, module, module.exports, noRequire, vpath.dirname(output.file), output.file, FakeSymbol, ...globalArgs);
Expand Down
1 change: 1 addition & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,7 @@ ${code}
const debug = new FourSlashInterface.Debug(state);
const format = new FourSlashInterface.Format(state);
const cancellation = new FourSlashInterface.Cancellation(state);
// tslint:disable-next-line:no-eval
const f = eval(wrappedCode);
f(test, goTo, plugins, verify, edit, debug, format, cancellation, FourSlashInterface.Classification, FourSlashInterface.Completion, verifyOperationIsCancelled);
}
Expand Down
1 change: 1 addition & 0 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Utils {
const environment = getExecutionEnvironment();
switch (environment) {
case ExecutionEnvironment.Browser:
// tslint:disable-next-line:no-eval
eval(fileContents);
break;
case ExecutionEnvironment.Node:
Expand Down
1 change: 1 addition & 0 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ namespace Harness.LanguageService {
}

setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any {
// tslint:disable-next-line:ban
return setTimeout(callback, ms, args);
}

Expand Down
2 changes: 2 additions & 0 deletions src/testRunner/parallel/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace Harness.Parallel.Host {
worker.timer = undefined;
}
else {
// tslint:disable-next-line:ban
worker.timer = setTimeout(killChild, data.payload.duration, data.payload);
}
break;
Expand Down Expand Up @@ -623,6 +624,7 @@ namespace Harness.Parallel.Host {
shimNoopTestInterface(global);
}

// tslint:disable-next-line:ban
setTimeout(() => startDelayed(perfData, totalCost), 0); // Do real startup on next tick, so all unit tests have been collected
}
}
1 change: 1 addition & 0 deletions src/tsserver/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ namespace ts.server {
// stat due to inconsistencies of fs.watch
// and efficiency of stat on modern filesystems
function startWatchTimer() {
// tslint:disable-next-line:ban
setInterval(() => {
let count = 0;
let nextToCheck = nextFileToCheck;
Expand Down
7 changes: 6 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"no-unnecessary-type-assertion": true,

"array-type": [true, "array"],
"ban": [
true,
"setInterval",
"setTimeout"
],
"ban-types": {
"options": [
["Object", "Avoid using the `Object` type. Did you mean `object`?"],
Expand Down Expand Up @@ -34,6 +39,7 @@
],
"no-bom": true,
"no-double-space": true,
"no-eval": true,
"no-in-operator": true,
"no-increment-decrement": true,
"no-inferrable-types": true,
Expand Down Expand Up @@ -100,7 +106,6 @@
"no-console": false,
"no-debugger": false,
"no-empty-interface": false,
"no-eval": false,
"no-object-literal-type-assertion": false,
"no-shadowed-variable": false,
"no-submodule-imports": false,
Expand Down