requireMatchingFunctionName: requires function names to match member and property names #850
Conversation
e491f51
to
083c63a
Compare
… function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
083c63a
to
6c57462
Compare
… function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
6c57462
to
f54d69a
Compare
… function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
|
||
function checkForMember(assignment, errors) { | ||
// anonymous function OR names mismatch | ||
if (!assignment.right.id || (assignment.left.property.name !== assignment.right.id.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.
I think the first clause mandates too much. This rule now enforces disallowAnonymousFunctions
and requireFunctionNameMatch
.
What do you think about this rule enforcing that if a function expression is named, its name must match the assignment property or member?
Great work @xaka! This is a very clear implementation. I left one comment on the scope of what this rule handles. Once that's addressed, it looks good to land; I'll wait for another reviewer to give the +1 before merging. |
I'm also concerned that this rule is bloat, which isn't to say it's not a good rule, but now that we have a sane plugin infra we should be more discriminating. |
Also, what if the property name is a reserved word. Named function expressions can't have those as function names while properties can, right? |
Thanks for constructive feedback! |
f54d69a
to
b636959
Compare
…tch function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
b636959
to
6422e23
Compare
…tch function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
6422e23
to
79a6499
Compare
…tch function names Example of member name mismatch: ```js function Test() {}; Test.prototype.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
I've updated the code. I wish I could change the branch name w/o opening another PR so for now it'll be the only mismatching place. |
We have some helpful lists in |
79a6499
to
a2e6501
Compare
…and property names Example of member name mismatch: ```js var test = {}; test.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
I've updated the code and documentation. So now when reserved work is detected, we just skip it. I've also added a suggestion to prefix such names with |
@xaka, thanks again for contributing. Please remove the |
a2e6501
to
86f85fb
Compare
…and property names Example of member name mismatch: ```js var test = {}; test.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
@mikesherov done, sir! |
// object.foo = function bar() {} | ||
// object['foo'] = function bar() {} | ||
case 'AssignmentExpression': | ||
checker = checkForMember; |
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.
just call checkForMember(node.parentNode, errors);
here;
@xaka just a couple of more comments and a rebase should bring this one across the finish line. Thanks again for contributing! |
86f85fb
to
4749849
Compare
…and property names Example of member name mismatch: ```js var test = {}; test.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
…and property names Example of member name mismatch: ```js var test = {}; test.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
4749849
to
2b52452
Compare
@mikesherov Done. Please double-check the documentation part as you changed the way it's generated and I did my best to follow the same path. |
@mikesherov are we good here? |
Thank you for the patience! And sorry it took that long to land. |
Requires function names to match member and property names Example of member name mismatch: ```js var test = {}; test.foo = function bar() {}; ``` Example of property name mismatch: ```js var test = {foo: function bar() {}}; ``` Fixes jscs-dev#846 Closes jscs-dev#850
Example of member name mismatch:
Example of property name mismatch:
Fixes #846
Closes #850