This cop checks for underscore-prefixed variables that are actually used.
# File lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb, line 14 def after_leaving_scope(scope, _variable_table) scope.variables.each_value do |variable| check_variable(variable) end end
# File lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb, line 20 def check_variable(variable) return unless variable.name.to_s.start_with?('_') return if variable.references.empty? return if variable.references.none?(&:explicit?) node = variable.declaration_node location = if node.type == :match_with_lvasgn node.children.first.loc.expression else node.loc.name end add_offense(nil, location) end
Generated with the Darkfish Rdoc Generator 2.