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] handle the Function type #2435

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) {
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
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