Skip to content

Commit

Permalink
fix(eslint-plugin): [no-implied-eval] permit more expression types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jas14 committed Aug 1, 2021
1 parent 62bcc93 commit ca7c549
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/eslint-plugin/src/rules/no-implied-eval.ts
Expand Up @@ -112,16 +112,15 @@ export default util.createRule({
case AST_NODE_TYPES.FunctionExpression:
return true;

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

case AST_NODE_TYPES.CallExpression:
return isBind(node.callee) || isFunctionType(node);

default:
return false;
return isFunctionType(node);
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/eslint-plugin/tests/rules/no-implied-eval.test.ts
Expand Up @@ -256,6 +256,7 @@ const foo = () => {};
const bar = () => {};
setTimeout(Math.radom() > 0.5 ? foo : bar, 0);
setTimeout(foo || bar, 500);
`,
`
class Foo {
Expand Down Expand Up @@ -816,6 +817,21 @@ globalThis['execScript'](\`\`);
},
],
},
{
code: `
const foo: string | undefined = 'hello';
const bar = () => {};
setTimeout(foo || bar, 500);
`,
errors: [
{
messageId: 'noImpliedEvalError',
line: 5,
column: 12,
},
],
},
{
code: 'const fn = Function();',
errors: [
Expand Down

0 comments on commit ca7c549

Please sign in to comment.