You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RuboCop’s InternalAffairs/NodeDestructuring cop tells me to “Use the methods provided with the node extensions instead of manually destructuring nodes” on the mlhs, values = *node line. But the RuboCop::AST::Node class doesn’t really offer any specialised helper method for this type of node.
So I thought it may be useful to add a RuboCop::AST::MasgnNode class with access to the left-hand-side list (also a RuboCop::AST::Node instance) and the right-hand-side RuboCop::AST::ArrayNode of values? And perhaps the class could also have a method to iterate over each assignment pair, much like the mlhs.to_a.zip(values.to_a).each, though perhaps it should be lazy instead of eager.
The text was updated successfully, but these errors were encountered:
Sure, this could be a good addition, although it is tricky.
Are you up to produce a PR?
mlhs seems easiest.
It might be nice to have a shortcut to mlhs's children, but I'm not sure what's a good name.
On the right side it's a bit tricky, as it may be an expression, or may be array.
The enumerator sounds interesting, but is trickiest, as there are multiple "unhappy" cases:
non array rhs (a, b = c): what does the enumerator do?
lhs has less elements than rhs (shortest example: a, = b, c): what does the enumerator do? 3) lhs has more elements than rhs seems really silly, but we have to wonder what to do in that case too.
lhs has more elements than rhs (shortest example: a, b = *c): what does the enumerator do?
I had started working on nodes for masgn/mlhs a couple years ago in #203 FWIW (looks like there were some open comments that I missed). It might be a good starting point, or it can be closed.
Do we need a node to help with “multi-assignment”? I came across this code in the rubocop-thread_safety gem: https://github.com/rubocop/rubocop-thread_safety/blob/2662a8142f41a53bc3bc65eb2c670db18b3c581a/lib/rubocop/cop/thread_safety/mutable_class_instance_variable.rb#L99C13-L110
RuboCop’s
InternalAffairs/NodeDestructuring
cop tells me to “Use the methods provided with the node extensions instead of manually destructuring nodes” on themlhs, values = *node
line. But theRuboCop::AST::Node
class doesn’t really offer any specialised helper method for this type of node.So I thought it may be useful to add a
RuboCop::AST::MasgnNode
class with access to the left-hand-side list (also aRuboCop::AST::Node
instance) and the right-hand-sideRuboCop::AST::ArrayNode
of values? And perhaps the class could also have a method to iterate over each assignment pair, much like themlhs.to_a.zip(values.to_a).each
, though perhaps it should be lazy instead of eager.The text was updated successfully, but these errors were encountered: