Skip to content

Commit

Permalink
fix(eslint-plugin): [no-implied-eval] handle conditional expression (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan authored Mar 1, 2021
1 parent 4ca5888 commit 8c65d30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 8c65d30

Please sign in to comment.