Skip to content

[no-implied-eval] False positive when importing symbol with name Function #2338

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

Closed
marcogrcr opened this issue Jul 29, 2020 · 3 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@marcogrcr
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/no-implied-eval": "error"
  }
}
import { Function } from "@aws-cdk/aws-lambda";

new Function(scope, "MyLambdaFunction", { /* ... */ });

Expected Result The rule detects that the imported Function is not global Function (either from the import or the parameters).

Actual Result The following error is logged:

error    Implied eval. Do not use the Function constructor to create functions  @typescript-eslint/no-implied-eval

Additional Info

This if statement is evaluating to true:

if (calleeName === FUNCTION_CONSTRUCTOR) {
context.report({ node, messageId: 'noFunctionConstructor' });
return;
}

Versions

package version
@typescript-eslint/eslint-plugin 3.6.0
@typescript-eslint/parser 3.6.0
TypeScript 3.9.6
ESLint 7.4.0
node 12.13.0
npm 6.12.0
@marcogrcr marcogrcr added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jul 29, 2020
@bradzacher
Copy link
Member

wow - did they really call a part of their API Function? That seems so silly to have a name clash like that.

This isn't that hard to fix - we already do a similar check in no-throw-literal to ensure the type is the library type and not an imported type:

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

Happy to accept a PR!

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Jul 29, 2020
@soobing
Copy link
Contributor

soobing commented Aug 2, 2020

@bradzacher I made PR 💗

@soobing
Copy link
Contributor

soobing commented Aug 22, 2020

This issue should be closed. @bradzacher

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants