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))
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning
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 |
# 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 convention(args.children[0], :expression, sprintf(MSG, name)) end end |