Class: Rubocop::Cop::Style::ColonMethodCall
- Defined in:
- lib/rubocop/cop/style/colon_method_call.rb
Overview
This cop checks for methods invoked via the :: operator instead of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).
Constant Summary collapse
- MSG =
'Do not use :: for method calls.'
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #corrections, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, 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
#allowed_name(method_name) ⇒ Object
22 23 24 |
# File 'lib/rubocop/cop/style/colon_method_call.rb', line 22 def allowed_name(method_name) method_name.match(/^[A-Z]/) end |
#autocorrect_action(node) ⇒ Object
26 27 28 29 30 |
# File 'lib/rubocop/cop/style/colon_method_call.rb', line 26 def autocorrect_action(node) @corrections << lambda do |corrector| corrector.replace(node.loc.dot, '.') end end |
#on_send(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubocop/cop/style/colon_method_call.rb', line 11 def on_send(node) receiver, _method_name, *_args = *node # discard methods with nil receivers and op methods(like []) return unless receiver && node.loc.dot && node.loc.dot.is?('::') return if allowed_name(_method_name.to_s) add_offence(:convention, node.loc.dot, MSG) do_autocorrect(node) end |