Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/no-implied-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default util.createRule({

case AST_NODE_TYPES.MemberExpression:
case AST_NODE_TYPES.Identifier:
case AST_NODE_TYPES.ConditionalExpression:
return isFunctionType(node);

case AST_NODE_TYPES.CallExpression:
Expand Down
21 changes: 21 additions & 0 deletions packages/eslint-plugin/tests/rules/no-implied-eval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ const foo = (callback: Function) => {
setTimeout(callback, 0);
};
`,
`
const foo = () => {};
const bar = () => {};

setTimeout(Math.radom() > 0.5 ? foo : bar, 0);
`,
],

invalid: [
Expand Down Expand Up @@ -606,6 +612,21 @@ const fn = (foo: string | any) => {
},
{
code: `
const foo = 'foo';
const bar = () => {};

setTimeout(Math.radom() > 0.5 ? foo : bar, 0);
`,
errors: [
{
messageId: 'noImpliedEvalError',
line: 5,
column: 12,
},
],
},
{
code: `
window.setTimeout(\`\`, 0);
window['setTimeout'](\`\`, 0);

Expand Down