-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Update: no-new-func
rule catching eval case of MemberExpression
#14860
Conversation
Hi @archmoj!, thanks for the Pull Request The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
Read more about contributing to ESLint here |
80b2c35
to
d20c16e
Compare
Hi @archmoj!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
Read more about contributing to ESLint here |
no-new-func
rule catching eval case of MemberExpression
Hi @archmoj, thanks for the PR! This change makes sense to me 👍, but I think we should treat it as an enhancement, so I'd like to hear more opinions from the team before accepting and reviewing the PR. |
I’m okay with the change, but the docs need to be updated to explain that these forms are akin to “new Function”. |
Good call. Addressed in cc988e1. |
Is there any remaining item(s) on this PR? |
We just need time to review it. A lot of people are away, so it may take some time. We'll update if we need any further changes. |
Thanks very much for the info @nzakas |
Do we have a consensus? I'm willing to champion this enhancement, but it needs one more 👍 Or, shall we treat it as a bug fix? |
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.
I agree the rule should catch this case. Thanks for adding the check! Since it’s improving the rule’s ability to detect eval-like calls, I’d lean toward this being a semver-minor change.
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.
Sorry for the delay! This looks very good, I left several comments about certain details.
lib/rules/no-new-func.js
Outdated
parent.type === "CallExpression" | ||
)) { | ||
evalNode = parent; | ||
} else if (parent.type === "MemberExpression" && node === parent.object) { |
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.
I think we should also check if the property name is one of "call"
, "apply"
or "bind"
, as this looks like a false positive:
/* eslint no-new-func: error */
Function.toString(); // false positive
For this check, we can use astUtils.getStaticPropertyName()
so that it covers code such as Function["call"]()
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@archmoj I think #14860 (comment) is the last remaining issue, let us know if you need any help with that. |
I would appreciate if you could possibly push a commit to address that. |
Done e6421b3 |
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!
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.
Looks good. Thanks for contributing.
no-new-func
rule catching eval case of MemberExpression
no-new-func
rule catching eval case of MemberExpression
Merged, thanks for contributing! This will be included in ESLint v8.0.0-rc.0 release, scheduled for tomorrow (#15059) |
Thanks very much @mdjermanovic for taking over this PR as well as the note. |
@archmoj we'd like to thank you for your work on this. Can you drop us an email at contact (at) eslint (dot) org? |
It was not really a big deal to kick start a PR like this one. |
We’d like to pay you from our contributor pool, but we need an email address to do that. :) |
What is the purpose of this pull request? (put an "X" next to an item)
[x] Bug fix (template)
[x] Include tests for this change
[x] Update documentation for this change
What changes did you make? (Give an overview)
The
no-new-func
rule should be able to catch calls toFunction.apply
(see the example below) concerning dynamic Function() constructor in the form of eval().Is there anything you'd like reviewers to focus on?
This would allow testing libraries to comply with CSP as demonstrated in plotly/plotly.js#5868
cc: @alexcjohnson