Class: RuboCop::Cop::Yattho::ComponentNameMigration

Inherits:
BaseCop
  • Object
show all
Defined in:
lib/rubocop/cop/yattho/component_name_migration.rb

Overview

This cop ensures that components don’t use deprecated component names

bad Yattho::ComponentNameComponent.new()

good Yattho::Beta::ComponentName.new()

Instance Method Summary collapse

Methods inherited from BaseCop

#valid_node?

Instance Method Details

#autocorrect(node) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rubocop/cop/yattho/component_name_migration.rb', line 25

def autocorrect(node)
  lambda do |corrector|
    component_name = node.const_name
    return unless ::Yattho::Deprecations.correctable?(component_name)

    replacement = ::Yattho::Deprecations.replacement(component_name)
    corrector.replace(node, replacement) if replacement.present?
  end
end

#on_send(node) ⇒ Object



18
19
20
21
22
23
# File 'lib/rubocop/cop/yattho/component_name_migration.rb', line 18

def on_send(node)
  return unless node.method_name == :new && !node.receiver.nil? && ::Yattho::Deprecations.deprecated?(node.receiver.const_name)

  message = ::Yattho::Deprecations.deprecation_message(node.receiver.const_name)
  add_offense(node.receiver, message: message)
end