Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-implied-eval] permit more expression types #3624

Merged
merged 2 commits into from
Aug 1, 2021
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
9 changes: 4 additions & 5 deletions packages/eslint-plugin/src/rules/no-implied-eval.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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