Skip to content

Commit f46fc6c

Browse files
fix: report only global references in no-implied-eval (#19932)
* fix: report only global references in no-implied-eval * chore: fix formatting * test: add more cases * docs: fix examples * chore: apply suggestions from code review Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 86e7426 commit f46fc6c

File tree

3 files changed

+308
-50
lines changed

3 files changed

+308
-50
lines changed

docs/src/rules/no-implied-eval.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Examples of **incorrect** code for this rule:
3535

3636
```js
3737
/*eslint no-implied-eval: "error"*/
38-
/*global window*/
38+
/*global window, setTimeout, setInterval, execScript*/
3939

4040
setTimeout("alert('Hi!');", 100);
4141

@@ -56,6 +56,7 @@ Examples of **correct** code for this rule:
5656

5757
```js
5858
/*eslint no-implied-eval: "error"*/
59+
/*global setTimeout, setInterval*/
5960

6061
setTimeout(function() {
6162
alert("Hi!");

lib/rules/no-implied-eval.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ module.exports = {
145145
return {
146146
CallExpression(node) {
147147
if (
148-
astUtils.isSpecificId(node.callee, EVAL_LIKE_FUNC_PATTERN)
148+
astUtils.isSpecificId(
149+
node.callee,
150+
EVAL_LIKE_FUNC_PATTERN,
151+
) &&
152+
sourceCode.isGlobalReference(node.callee)
149153
) {
150154
reportImpliedEvalCallExpression(node);
151155
}

0 commit comments

Comments
 (0)