diff --git a/packages/eslint-plugin/src/rules/no-implied-eval.ts b/packages/eslint-plugin/src/rules/no-implied-eval.ts index dee23d62d275..f4cafd3e3735 100644 --- a/packages/eslint-plugin/src/rules/no-implied-eval.ts +++ b/packages/eslint-plugin/src/rules/no-implied-eval.ts @@ -3,7 +3,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; -import { createRule, getParserServices } from '../util'; +import { createRule, getParserServices, isBuiltinSymbolLike } from '../util'; const FUNCTION_CONSTRUCTOR = 'Function'; const GLOBAL_CANDIDATES = new Set(['global', 'window', 'globalThis']); @@ -75,15 +75,8 @@ export default createRule({ return true; } - // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison - if (symbol && symbol.escapedName === FUNCTION_CONSTRUCTOR) { - const declarations = symbol.getDeclarations() ?? []; - for (const declaration of declarations) { - const sourceFile = declaration.getSourceFile(); - if (services.program.isSourceFileDefaultLibrary(sourceFile)) { - return true; - } - } + if (isBuiltinSymbolLike(services.program, type, FUNCTION_CONSTRUCTOR)) { + return true; } const signatures = checker.getSignaturesOfType( @@ -143,13 +136,11 @@ export default createRule({ const type = services.getTypeAtLocation(node.callee); const symbol = type.getSymbol(); if (symbol) { - const declarations = symbol.getDeclarations() ?? []; - for (const declaration of declarations) { - const sourceFile = declaration.getSourceFile(); - if (services.program.isSourceFileDefaultLibrary(sourceFile)) { - context.report({ node, messageId: 'noFunctionConstructor' }); - return; - } + if ( + isBuiltinSymbolLike(services.program, type, 'FunctionConstructor') + ) { + context.report({ node, messageId: 'noFunctionConstructor' }); + return; } } else { context.report({ node, messageId: 'noFunctionConstructor' });