Sha256: 7f0c9a5c854d327107b6ed748a75307a47dba3c9f463893642429d68d6056e76

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 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::HiddenTextExpander" => "Primer::Alpha::HiddenTextExpander",
          "Primer::DetailsComponent" => "Primer::Beta::Details",
          "Primer::HeadingComponent" => "Primer::Beta::Heading",
          "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::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

2 entries across 2 versions & 1 rubygems

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