Sha256: 7d315e8f0936db1ed491c2b937f48ec8365f6a628a6473a56b710a9ec450d0be

Contents?: true

Size: 882 Bytes

Versions: 6

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require "rubocop"

# :nocov:
module RuboCop
  module Cop
    module Ariadne
      # This cop ensures that components don't use deprecated component names
      #
      # bad
      # Ariadne::ComponentNameComponent.new()
      #
      # good
      # Ariadne::Beta::ComponentName.new()
      class ComponentNameMigration < BaseCop
        DEPRECATIONS = {
          "Ariadne::TestComponent" => "Ariadne::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

6 entries across 6 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.6 lib/rubocop/cop/ariadne/component_name_migration.rb
ariadne_view_components-0.0.5 lib/rubocop/cop/ariadne/component_name_migration.rb
ariadne_view_components-0.0.4 lib/rubocop/cop/ariadne/component_name_migration.rb
ariadne_view_components-0.0.3 lib/rubocop/cop/ariadne/component_name_migration.rb
ariadne_view_components-0.0.2 lib/rubocop/cop/ariadne/component_name_migration.rb
ariadne_view_components-0.0.1 lib/rubocop/cop/ariadne/component_name_migration.rb