Class: RuboCop::Cop::UmtsCustomCops::BeMatcherForNonDuplicableTypes

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb

Overview

Prefer the easier-to-read be matcher for non-duplicable types.

See the specs for examples.

Constant Summary collapse

MSG =
'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



24
25
26
27
28
29
# File 'lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb', line 24

def autocorrect(node)
  lambda do |corrector|
    matcher = node.child_nodes[1]
    corrector.replace matcher.loc.selector, 'be'
  end
end

#on_send(node) ⇒ Object



31
32
33
34
35
# File 'lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb', line 31

def on_send(node)
  return unless eq_on_non_duplicable_type? node

  add_offense node, location: :expression, message: MSG
end