Skip to content

Commit 8c65d30

Browse files
authored
fix(eslint-plugin): [no-implied-eval] handle conditional expression (typescript-eslint#3125)
1 parent 4ca5888 commit 8c65d30

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/eslint-plugin/src/rules/no-implied-eval.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default util.createRule({
108108

109109
case AST_NODE_TYPES.MemberExpression:
110110
case AST_NODE_TYPES.Identifier:
111+
case AST_NODE_TYPES.ConditionalExpression:
111112
return isFunctionType(node);
112113

113114
case AST_NODE_TYPES.CallExpression:

packages/eslint-plugin/tests/rules/no-implied-eval.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ const foo = (callback: Function) => {
251251
setTimeout(callback, 0);
252252
};
253253
`,
254+
`
255+
const foo = () => {};
256+
const bar = () => {};
257+
258+
setTimeout(Math.radom() > 0.5 ? foo : bar, 0);
259+
`,
254260
],
255261

256262
invalid: [
@@ -606,6 +612,21 @@ const fn = (foo: string | any) => {
606612
},
607613
{
608614
code: `
615+
const foo = 'foo';
616+
const bar = () => {};
617+
618+
setTimeout(Math.radom() > 0.5 ? foo : bar, 0);
619+
`,
620+
errors: [
621+
{
622+
messageId: 'noImpliedEvalError',
623+
line: 5,
624+
column: 12,
625+
},
626+
],
627+
},
628+
{
629+
code: `
609630
window.setTimeout(\`\`, 0);
610631
window['setTimeout'](\`\`, 0);
611632

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy