Skip to content

Commit 8c65d30

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

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

+1
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:

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

+21
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)