Sha256: ab0173728d7cfcd38faedd51b8a0e56763479c7788204b1124bd89f6e9ac6869

Contents?: true

Size: 1.07 KB

Versions: 145

Compression:

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

          message = ::Primer::Deprecations.deprecation_message(node.receiver.const_name)
          add_offense(node.receiver, message: message)
        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

145 entries across 145 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.52.2 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.36.4 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.52.1 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.52.0 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.36.3 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.51.0 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.36.2 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.50.1 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.50.0 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.36.1 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.36.0 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.49.2 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.35.2 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.49.1 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.49.0 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.35.1 lib/rubocop/cop/primer/component_name_migration.rb
primer_view_components-0.35.0 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.48.2 lib/rubocop/cop/primer/component_name_migration.rb
openproject-primer_view_components-0.48.1 lib/rubocop/cop/primer/component_name_migration.rb