class RuboCop::Cop::Lint::ShadowingOuterLocalVariable
end
end
do_something(bar)
2.times do |bar|
foo = 1
def some_method
# good
@example
end
end
do_something(foo)
2.times do |foo| # shadowing outer ‘foo`
foo = 1
def some_method
# bad
@example
“shadowing outer local variable - foo” from `ruby -cw`.
This is a mimic of the warning
for block arguments or block local variables.
This cop looks for use of the same name as outer local variables
def before_declaring_variable(variable, variable_table)
def before_declaring_variable(variable, variable_table) return if variable.should_be_unused? outer_local_variable = variable_table.find_variable(variable.name) return unless outer_local_variable message = format(MSG, variable: variable.name) add_offense(variable.declaration_node, message: message) end
def join_force?(force_class)
def join_force?(force_class) force_class == VariableForce end