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

Conversation

soobing
Copy link
Contributor

@soobing soobing commented Aug 29, 2020

Fixes #2358
In case of using Function type the function checking is function type( named isFunctionType ) should return true.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @soobing!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Aug 29, 2020

Codecov Report

Merging #2435 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2435      +/-   ##
==========================================
- Coverage   92.81%   92.80%   -0.02%     
==========================================
  Files         290      290              
  Lines        9453     9459       +6     
  Branches     2647     2650       +3     
==========================================
+ Hits         8774     8778       +4     
  Misses        322      322              
- Partials      357      359       +2     
Flag Coverage Δ
#unittest 92.80% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/no-implied-eval.ts 93.75% <ø> (-2.81%) ⬇️

Comment on lines 87 to 90
ts.SymbolFlags.FunctionScopedVariable |
ts.SymbolFlags.Interface |
ts.SymbolFlags.Transient,
) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have any good idea to check symbol.flags === 33554497 please let me know. ✨

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better instead to just do something similar to what we've got for checking if the symbol is declared locally or not:

const declarations = symbol.getDeclarations() ?? [];
for (const declaration of declarations) {
const sourceFile = declaration.getSourceFile();
if (program.isSourceFileDefaultLibrary(sourceFile)) {
context.report({ node, messageId: 'noFunctionConstructor' });
return;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradzacher Thank you for review. I updated to check if the symbol is declared locally or not :)

@soobing soobing changed the title [no-implied-eval] In 'isFunctionType' function should return 'true' when using Function type of typescript fix(no-implied-eval): In 'isFunctionType' function should return 'true' when using Function type of typescript Aug 29, 2020
@bradzacher bradzacher added the bug Something isn't working label Aug 29, 2020
@bradzacher bradzacher changed the title fix(no-implied-eval): In 'isFunctionType' function should return 'true' when using Function type of typescript fix(eslint-plugin): [no-implied-eval] handle the Function type Aug 29, 2020
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Sep 6, 2020
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Sep 8, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for your contribution!

@bradzacher bradzacher merged commit e1401dc into typescript-eslint:master Sep 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-implied-eval] False positive with callback: Function
2 participants