Disallow the use of eval()-like methods.
The setTimeout(), setInterval(), setImmediate(), or execScript() function accept a string as its first parameter. For example:
setTimeout('alert(`Hi!`);', 100); This behavior is considered implicit eval() and is not recommended.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-implied-eval": "error"
}
} function alert(arg: string) {
console.log(arg);
}
const time = 100;
setTimeout(() => {
alert('Hi!');
}, time);
setInterval(() => {
alert('Hi!');
}, time);
const fn = () => {
console.info('fn');
};
setTimeout(fn, time);
class Foo {
public static fn = () => {
console.info('static');
};
public meth() {
console.info('method');
}
}
setTimeout(Foo.fn, time); const time = 100;
setTimeout('alert(`Hi!`);', time);
setInterval('alert(`Hi!`);', time);
const fn1 = '() = {}';
setTimeout(fn1, time);
const fn2 = () => {
return 'x = 10';
};
setTimeout(fn2(), time);
export const fn3 = new Function('a', 'b', 'return a + b'); plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.