class RuboCop::Cop::Lint::AssignmentInCondition
if/while/until.
This cop checks for assignments in the conditions of
def check(node)
def check(node) condition, = *node # assignments inside blocks are not what we're looking for return if condition.type == :block condition.each_node(:begin, *EQUALS_ASGN_NODES) do |asgn_node| # skip safe assignment nodes if safe assignment is allowed return if safe_assignment_allowed? && safe_assignment?(asgn_node) # assignment nodes from shorthand ops like ||= don't have operator if asgn_node.type != :begin && asgn_node.loc.operator add_offense(asgn_node, :operator) end end end
def on_if(node)
def on_if(node) check(node) end
def on_until(node)
def on_until(node) check(node) end
def on_while(node)
def on_while(node) check(node) end