Sha256: 4e9970a4bbc111eed00c32b25f1b27552d7dfe5e0a3e6d7df2f52431c9d029c5

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 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)

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
primer_view_components-0.0.116 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.115 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.114 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.113 lib/rubocop/cop/primer/component_name_migration.rb