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) #5872
Conversation
By analyzing the blame information on this pull request, we identified @nzakas, @scriptdaemon and @alberto to be potential reviewers |
LGTM |
@@ -0,0 +1,73 @@ | |||
# Disallow certain object properties (no-restricted-properties) | |||
|
|||
Certain properties on objects may be disallowed in a codebase. This is useful for deprecating an API or restricting usage of a module's methods. This rule looks for accessing a given property key on a given object name, either when reading the property's value or invoking it as a function. You may specify an optional message to indicate an alternative API or a reason for the restriction. |
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.
Can you give an example here to make this concrete? Like, location.href
for example? (or something better?)
Overall looks good, just a few comments. |
@@ -190,6 +190,7 @@ These rules are purely matters of style and are quite subjective. | |||
* [no-nested-ternary](no-nested-ternary.md): disallow nested ternary expressions | |||
* [no-new-object](no-new-object.md): disallow `Object` constructors | |||
* [no-plusplus](no-plusplus.md): disallow the unary operators `++` and `--` | |||
* [no-restricted-properties](no-restricted-properties.md) - disallow use of specified object 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.
disallow the use of specified object properties
After recent editing, most (but not quite all) occurrences of use are preceded by the.
Extra word :( but helps make clear it is a noun not a verb, especially if English is not first language of reader :)
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 like it, great input. I'll update this.
@willklein Thank you for investing the time and effort to research and follow existing precedents for the rule doc. Most of the line comments represent improvements we are in the middle of making, so by your extra effort right now, you level up with a rising tide, and save rework in the coming weeks. Thanks :) |
@nzakas Good question about options. Although we are moving away from separate examples of json config, this is parallel with no-restricted-syntax, so let’s say it’s good to go for this PR. As we edit rules with simpler options schema, we gain experience for the more complex schema. |
Another thing that came to mind is reference to properties by object destructuring:
|
@willklein just checking in to see if you're still working on this? |
@willklein when you get a chance, can you sign our new CLA? http://contribute.jquery.org/cla |
@nzakas, yes and yes. |
@willklein just checking to see if you are planning on finishing this up. |
```json | ||
{ | ||
"rules": { | ||
"no-restricted-properties": [2, [{ |
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 might be the wrong time to bring this up, but could the option syntax be simplified like so:
// ...
"no-restricted-properties": [ "error", [ {
"objectName": {
"propertyName1": "Error message 1",
"propertyName2": "Error message 2"
},
"anotherObjectName": {
// ...
}, // etc
} ] ],
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.
Please add that feedback to the issue.
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.
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.
@aubergine10 #3218
@willklein last ping, I promise. :) If you aren't able to finish this up, can you just sign the jQuery CLA? That way, someone can continue your work and finish it up. |
Unfortunately, no response and without the CLA signed, we can't use the code. @willklein feel free to reopen if you'd like to continue. |
Sorry all, @nzakas. I signed the jQuery CLA so my code can be picked up. I had a baby, then started a new job, so this year has been crazy for me. Making open source a part of what we do @Crownpeak but I'm focused on building the Denver team instead of coding right now. |
Thanks, @willklein, we understand, life happens :). @nzakas the bot didn't pick it. Maybe it is because the issue is closed? Is there any way we can confirm the CLA signature is ok? |
Fixes #3218.
Let me know if there's anything to address. Thanks!