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

New: no-restricted-properties rule (fixes #3218) #7017

Merged
merged 7 commits into from Sep 2, 2016

Conversation

TheSavior
Copy link
Contributor

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.

@mention-bot
Copy link

@TheSavior, thanks for your PR! By analyzing the annotation information on this pull request, we identified @nzakas, @alberto and @mysticatea to be potential reviewers

@eslintbot
Copy link

LGTM

@jquerybot
Copy link

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.

@TheSavior
Copy link
Contributor Author

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!

@willklein
Copy link

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)
Copy link
Member

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)

@nzakas
Copy link
Member

nzakas commented Aug 30, 2016

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.

@eslintbot
Copy link

LGTM

@TheSavior
Copy link
Contributor Author

Thanks for the review. All addressed.

@nzakas
Copy link
Member

nzakas commented Aug 31, 2016

Looks like you have some linting errors in the markdown file, can you take a look?

@eslintbot
Copy link

LGTM

@TheSavior
Copy link
Contributor Author

TheSavior commented Aug 31, 2016

Any idea why the CLA started failing?

Edit
Looks like the CLA Page is 404ing: http://contribute.jquery.org/CLA/status/?owner=eslint&repo=eslint&sha=a938c40e1445fe40224b4ce35461692e1c8ad1dc

@eslintbot
Copy link

LGTM

@TheSavior
Copy link
Contributor Author

Rebuilding didn't solve the CLA issue. Is it something on the bot's side?

@platinumazure
Copy link
Member

@TheSavior Yes, I think either the CLA bot or the CLA website is broken. @kborchers is already looking into this a different ESLint PR.

@kborchers
Copy link

CLA check has been fixed. Sorry about that all.

};

return restrictions;
}, {});
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, good catch.

Copy link
Contributor Author

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. 👍

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member

LGTM now 😄
I'd like someone else to verify.

return {
MemberExpression(node) {
const objectName = node.object && node.object.name;
const propertyName = node.property && node.property.name;
Copy link
Member

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?

Copy link
Member

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
.

@eslintbot
Copy link

LGTM

@nzakas
Copy link
Member

nzakas commented Sep 2, 2016

Lgtm. Thanks for picking this up @TheSavior !

@nzakas nzakas merged commit 46cb690 into eslint:master Sep 2, 2016
@TheSavior TheSavior deleted the issue3218 branch September 2, 2016 16:42
@dinoboff
Copy link

Nice addition.

Why is it in the "Node.js and CommonJS" category?

@vitorbal
Copy link
Member

@dinoboff this has since been fixed by #7118

@dinoboff
Copy link

Thanks.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet