Skip to content

Commit

Permalink
fix(eslint-plugin): [no-implied-eval] handle the Function type (#2435)
Browse files Browse the repository at this point in the history
  • Loading branch information
soobing committed Sep 14, 2020
1 parent 7ca54c3 commit e1401dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/eslint-plugin/src/rules/no-implied-eval.ts
Expand Up @@ -80,6 +80,16 @@ export default util.createRule({
return true;
}

if (symbol && symbol.escapedName === FUNCTION_CONSTRUCTOR) {
const declarations = symbol.getDeclarations() ?? [];
for (const declaration of declarations) {
const sourceFile = declaration.getSourceFile();
if (program.isSourceFileDefaultLibrary(sourceFile)) {
return true;
}
}
}

const signatures = checker.getSignaturesOfType(
type,
ts.SignatureKind.Call,
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/tests/rules/no-implied-eval.test.ts
Expand Up @@ -246,6 +246,11 @@ const fn = (foo: () => void) => {
import { Function } from './class';
new Function('foo');
`,
`
const foo = (callback: Function) => {
setTimeout(callback, 0);
};
`,
],

invalid: [
Expand Down

0 comments on commit e1401dc

Please sign in to comment.