Sha256: 95dced9c12c79f2789c337c57ac15308fdf5fa213381d8852e57125d25b90c52

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "rubocop"

# :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
        DEPRECATIONS = {
          "Primer::BoxComponent" => "Primer::Box",
          "Primer::ButtonGroup" => "Primer::Beta::ButtonGroup",
          "Primer::CloseButton" => "Primer::Beta::CloseButton",
          "Primer::CounterComponent" => "Primer::Beta::Counter",
          "Primer::BlankslateComponent" => "Primer::Beta::Blankslate",
          "Primer::BorderBoxComponent" => "Primer::Beta::BorderBox",
          "Primer::BaseButton" => "Primer::Beta::BaseButton",
          "Primer::TestComponent" => "Primer::Beta::Test"
        }.freeze

        def on_send(node)
          return unless node.method_name == :new && !node.receiver.nil? && DEPRECATIONS.key?(node.receiver.const_name)

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

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node, DEPRECATIONS[node.const_name])
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
primer_view_components-0.0.90 lib/rubocop/cop/primer/component_name_migration.rb