class Rubocop::Cop::Lint::UnusedLocalVariable

This cop looks for unused local variables in each scope. Actually this is a mimic of the warning “assigned but unused variable - foo” from ‘ruby -cw`.

Constants

MSG
TYPES_TO_ACCEPT_UNUSED

Public Instance Methods

after_leaving_scope(scope) click to toggle source
# File lib/rubocop/cop/lint/unused_local_variable.rb, line 20
def after_leaving_scope(scope)
  scope.variable_entries.each_value do |entry|
    next if entry.used?
    next if TYPES_TO_ACCEPT_UNUSED.include?(entry.node.type)
    next if entry.name.to_s.start_with?('_')
    message = sprintf(MSG, entry.name)
    add_offence(:warning, entry.node.loc.expression, message)
  end
end
inspect(source_buffer, source, tokens, ast, comments) click to toggle source
# File lib/rubocop/cop/lint/unused_local_variable.rb, line 16
def inspect(source_buffer, source, tokens, ast, comments)
  inspect_variables(ast)
end