Class: Rubocop::Cop::Lint::UselessAssignment

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/lint/useless_assignment.rb

Overview

This cop checks for useless assignment as the final expression of a function definition.

Examples:


def something
  x = 5
end

def something
  x = Something.new
  x.attr = 5
end

Constant Summary collapse

MSG =
'Useless assignment to local variable %s.'

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_def(node) ⇒ Object



22
23
24
25
26
# File 'lib/rubocop/cop/lint/useless_assignment.rb', line 22

def on_def(node)
  _name, _args, body = *node

  check_for_useless_assignment(body)
end

#on_defs(node) ⇒ Object



28
29
30
31
32
# File 'lib/rubocop/cop/lint/useless_assignment.rb', line 28

def on_defs(node)
  _target, _name, _args, body = *node

  check_for_useless_assignment(body)
end