-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [no-implied-eval] handle the Function
type
#2435
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
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 Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
ts.SymbolFlags.FunctionScopedVariable | | ||
ts.SymbolFlags.Interface | | ||
ts.SymbolFlags.Transient, | ||
) && |
There was a problem hiding this comment.
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. ✨
There was a problem hiding this comment.
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:
typescript-eslint/packages/eslint-plugin/src/rules/no-implied-eval.ts
Lines 128 to 135 in 2ada5af
const declarations = symbol.getDeclarations() ?? []; | |
for (const declaration of declarations) { | |
const sourceFile = declaration.getSourceFile(); | |
if (program.isSourceFileDefaultLibrary(sourceFile)) { | |
context.report({ node, messageId: 'noFunctionConstructor' }); | |
return; | |
} | |
} |
There was a problem hiding this comment.
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 :)
Function
type
There was a problem hiding this 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!
Fixes #2358
In case of using
Function type
the function checking is function type( namedisFunctionType
) should return true.