-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add MasgnNode
class for masgn
nodes
#203
Conversation
Sorry I missed this in my previous PR @marcandre 😅 🙌 |
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.
masgn
is complicated, isn't it? 😅
PR looks like a good start, but you seem to have overlooked 2 important cases: foo.bar, foo[:baz], ... = ...
.
Please describe results of your proposed methods and add tests.
Also:
-
each_descendant
should only be used on the first child. Please add a test forx, y = 1, z+=2
for example. Even then, some corner cases could be problematic:foo[x+=1], bar = ...
-
I doubt
each_assignment
is necessary. Performance of enumerators is typically quite poor, especially for short lists
I knew there were things I wasn't thinking of, thanks @marcandre I'll fix up for those cases! |
@marcandre updated now. I have now introduced a
I also added For symmetry, Please let me know your thoughts! |
0476aa2
to
8b5f9b3
Compare
The "modern" spec was failing on |
ff20438
to
4591b75
Compare
@marcandre it's been a long time but I updated this PR and tried to address your concerns/simplify some things. |
a430f91
to
61ae1f1
Compare
That's great @dvandersluis , good work. So a decision remains as to what we return for the LHS in the different cases:
|
I think for simplicity with
Is this what you had in mind @marcandre? |
Yes, I agree that's probably best 👍 |
Updated |
lib/rubocop/ast/node/masgn_node.rb
Outdated
end | ||
alias rhs expression | ||
|
||
# @return [Array<Node>] values being assigned on the RHS of the multiple assignment |
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 it would be worth explaining the subtle difference between expression
and values
, in particular that [1, 2]
vs 1, 2
(which expression
considers the same but values
doesn't)
So quick! A bit of extra doc and this is good to go. It's 2am here in Barcelona, so I'll look at it tomorrow 😅 |
Thanks as always for your quick reviews @marcandre! I updated with some more documentation on |
Very nice, thank you ❤️ |
Released v1.13.0 |
Now that rubocop-ast has a `MasgnNode` and a `MlhsNode`, we can remove some node destructuring from our code base. See rubocop/rubocop-ast#203 for the implementation.
Follows #201. I actually ended up needing
masgn
to have its own class withexpression
defined in order to do the refactoring I wanted to, so this adds it.Because
masgn
nodes are more involved than the other assignment types, this class has a different interface than the other assignments, except forexpression
which works the same. Rather thanname
that the other assignment classes have,MasgnNode
hasnames
(since there will inherently be more than one). It also is able to handle nestedmlhs
es.