Sha256: 62d96638bfe13e8752b6053771819984152dc86276dc833b2172b7874f406887

Contents?: true

Size: 1.15 KB

Versions: 184

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "rubocop"

# :nocov:
module RuboCop
  module Cop
    module Primer
      # This cop ensures that `ButtonComponent` doesn't use deprecated arguments.
      #
      # bad
      # ButtonComponent.new(variant: :small)
      #
      # good
      # ButtonComponent.new(size: :small)
      class DeprecatedButtonArguments < BaseCop
        INVALID_MESSAGE = <<~STR
          `variant` is deprecated. Use `size` instead.
        STR

        def_node_matcher :button_component?, <<~PATTERN
          (send (const (const nil? :Primer) :ButtonComponent) :new ...)
        PATTERN

        DEPRECATIONS = {
          variant: :size
        }.freeze

        def on_send(node)
          return unless button_component?(node)

          kwargs = node.arguments.last

          return if kwargs.nil?

          pair = kwargs.pairs.find { |x| x.key.value == :variant }

          return if pair.nil?

          add_offense(pair.key, message: INVALID_MESSAGE)
        end

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

Version data entries

184 entries across 184 versions & 2 rubygems

Version Path
primer_view_components-0.35.2 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.49.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.49.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
primer_view_components-0.35.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
primer_view_components-0.35.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.48.2 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.48.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.48.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.47.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.47.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
primer_view_components-0.34.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.46.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.46.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.45.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.44.3 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.44.2 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.44.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb
primer_view_components-0.33.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.44.0 lib/rubocop/cop/primer/deprecated_button_arguments.rb
openproject-primer_view_components-0.43.1 lib/rubocop/cop/primer/deprecated_button_arguments.rb