Skip to content

evals

Reports uses of the eval function.

✅ This rule is included in the ts logical and logicalStrict presets.

The eval() function evaluates a string as JavaScript code. This is dangerous because it can execute arbitrary code, potentially leading to security vulnerabilities.

Using eval() has several problems:

  • Security risks: executing untrusted code can lead to code injection attacks
  • Performance issues: eval() prevents JavaScript engine optimizations
  • Debugging difficulty: dynamically executed code is harder to debug and trace
  • CSP violations: many Content Security Policies prohibit eval()
const
const code: string
code
=
const getUserInput: () => string
getUserInput
();
function eval(x: string): any

Evaluates JavaScript code and executes it.

@paramx A String value that contains valid JavaScript code.

eval
(
const code: string
code
);
const
const result: any
result
=
function eval(x: string): any

Evaluates JavaScript code and executes it.

@paramx A String value that contains valid JavaScript code.

eval
("2 + 2");

This rule is not configurable.

In rare cases, eval() may be necessary for dynamic code execution, such as in development tools or REPLs. If you have a legitimate use case and understand the security implications, you may disable this rule for specific lines. Consider using the Function constructor as a slightly safer alternative, though it still carries risks.

Made with ❤️‍🔥 around the world by the Flint team and contributors.