Skip to content

Commit e1401dc

Browse files
authored
fix(eslint-plugin): [no-implied-eval] handle the Function type (typescript-eslint#2435)
1 parent 7ca54c3 commit e1401dc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/eslint-plugin/src/rules/no-implied-eval.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export default util.createRule({
8080
return true;
8181
}
8282

83+
if (symbol && symbol.escapedName === FUNCTION_CONSTRUCTOR) {
84+
const declarations = symbol.getDeclarations() ?? [];
85+
for (const declaration of declarations) {
86+
const sourceFile = declaration.getSourceFile();
87+
if (program.isSourceFileDefaultLibrary(sourceFile)) {
88+
return true;
89+
}
90+
}
91+
}
92+
8393
const signatures = checker.getSignaturesOfType(
8494
type,
8595
ts.SignatureKind.Call,

packages/eslint-plugin/tests/rules/no-implied-eval.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ const fn = (foo: () => void) => {
246246
import { Function } from './class';
247247
new Function('foo');
248248
`,
249+
`
250+
const foo = (callback: Function) => {
251+
setTimeout(callback, 0);
252+
};
253+
`,
249254
],
250255

251256
invalid: [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy