Sha256: 2fdeaaf1aab9e353bbd99ce935bc940270bf8fa64d1bbcd51cb6500ea42d5d29

Contents?: true

Size: 876 Bytes

Versions: 18

Compression:

Stored size: 876 Bytes

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::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

18 entries across 18 versions & 1 rubygems

Version Path
primer_view_components-0.0.85 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.84 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.83 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.82 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.81 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.80 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.79 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.78 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.77 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.76 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.75 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.74 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.73 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.72 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.71 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.70 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.69 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.0.68 lib/rubocop/cop/primer/component_name_migration.rb