Class: Rubocop::Cop::Style::OpMethod
- Defined in:
- lib/rubocop/cop/style/op_method.rb
Overview
This cop makes sure that certain operator methods have their sole parameter named other.
Constant Summary collapse
- MSG =
'When defining the %s operator, name its argument *other*.'
- BLACKLISTED =
[:+@, :-@, :[], :[]=, :<<]
- TARGET_ARGS =
s(:args, s(:arg, :other))
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, #inspect, lint?, #name, rails?, style?
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#on_def(node) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubocop/cop/style/op_method.rb', line 15 def on_def(node) name, args, _body = *node if name !~ /\A\w/ && !BLACKLISTED.include?(name) && args.children.size == 1 && args != TARGET_ARGS add_offence(:convention, args.children[0].loc.expression, sprintf(MSG, name)) end super end |