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
New: no-restricted-properties rule (fixes #3218) #7017
Conversation
@TheSavior, thanks for your PR! By analyzing the annotation information on this pull request, we identified @nzakas, @alberto and @mysticatea to be potential reviewers |
LGTM |
Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA). 📝 Please visit http://contribute.jquery.org/CLA/ to sign. After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know. If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, check the status of your CLA check. |
I have signed the CLA, but since the PR has a commit from @willklein, it requires him to sign it as well. @willklein If you get a chance to do that, it would be greatly appreciated! |
Sorry, I completed the CLA months ago but not for the email on the commit. All set! Thanks for picking this up. :) |
@@ -0,0 +1,73 @@ | |||
# Disallow certain object properties (no-restricted-properties) |
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.
Nitpick: Lowercase "d" to start the heading (new style)
This looks really good. Only comments are on the docs, just to get them inline with how we're doing documentation these days. If you can fix those up, I think this is ready to go. |
LGTM |
Thanks for the review. All addressed. |
Looks like you have some linting errors in the markdown file, can you take a look? |
LGTM |
Any idea why the CLA started failing? Edit |
LGTM |
Rebuilding didn't solve the CLA issue. Is it something on the bot's side? |
@TheSavior Yes, I think either the CLA bot or the CLA website is broken. @kborchers is already looking into this a different ESLint PR. |
CLA check has been fixed. Sorry about that all. |
}; | ||
|
||
return restrictions; | ||
}, {}); |
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 use Map
objects instead of plain objects.
/*eslint no-restricted-properties: [error, {object: "obj", property: "foo"}]*/
// should not warn.
toString.toString
obj.toString
obj.valueOf
/*eslint no-restricted-properties: [error, {object: "obj", property: "__proto__"}]*/
// should not warn.
obj.toString
obj.valueOf
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.
Wow, good catch.
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.
This has been great. This is the first time I have used Map
. This was a great use for it. 👍
LGTM |
LGTM now 😄 |
return { | ||
MemberExpression(node) { | ||
const objectName = node.object && node.object.name; | ||
const propertyName = node.property && node.property.name; |
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.
This is only going to catch foo.bar
notation. Should we also catch foo['bar']
as well?
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 @mysticatea had recently added a "get simple property name" method
to ast-utils, might want to hunt that down.
On Sep 2, 2016 8:56 AM, "Ilya Volodin" notifications@github.com wrote:
In lib/rules/no-restricted-properties.js
#7017 (comment):
if (!restrictions.has(objectName)) {
restrictions.set(objectName, new Map());
}
restrictions.get(objectName).set(propertyName, {
message: option.message
});
return restrictions;
}, new Map());
return {
MemberExpression(node) {
const objectName = node.object && node.object.name;
const propertyName = node.property && node.property.name;
This is only going to catch foo.bar notation. Should we also catch
foo['bar'] as well?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/eslint/eslint/pull/7017/files/576e4cc27d1d2f01961be20a41fa94df19a75b19#r77349937,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARWekx4AnK_LRONX9DtdWUi0el5Plroks5qmCsngaJpZM4JwEv3
.
LGTM |
Lgtm. Thanks for picking this up @TheSavior ! |
Nice addition. Why is it in the "Node.js and CommonJS" category? |
Thanks. |
What issue does this pull request address?
#3218
What changes did you make? (Give an overview)
Added a rule to disallow certain method calls on specific objects. For example
describe.only
in mocha.Is there anything you'd like reviewers to focus on?
Nope, should be pretty straight forward.
Extra thanks to @willklein. This is essentially all his code. I just updated it to the new syntax and made it pass the tests.