Sha256: 126e9a3dc55b75262c7d5bc579adc28692b5f0207063d37667c84f11599540d2

Contents?: true

Size: 1.04 KB

Versions: 19

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "rubocop"
require "primer/deprecations"

# :nocov:
module RuboCop
  module Cop
    module Primer
      # This cop ensures that components don't use deprecated component names
      #
      # bad
      # Primer::ComponentNameComponent.new()
      #
      # good
      # Primer::Beta::ComponentName.new()
      class ComponentNameMigration < BaseCop
        def on_send(node)
          return unless node.method_name == :new && !node.receiver.nil? && ::Primer::Deprecations.deprecated?(node.receiver.const_name)

          add_offense(node.receiver, message: "Don't use deprecated names")
        end

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

            suggested_component = ::Primer::Deprecations.suggested_component(component_name)
            corrector.replace(node, suggested_component) if suggested_component.present?
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
primer_view_components-0.0.112 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.111 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.110 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.109 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.108 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.107 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.106 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.105 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.104 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.103 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.102 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.101 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.100 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.99 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.98 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.97 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.96 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.95 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.94 lib/rubocop/cop/primer/component_name_migration.rb