Sha256: 665e8cd48533ea4c47074372aba093246db02920f5d1cf21e48bf6898bc4a58c

Contents?: true

Size: 979 Bytes

Versions: 114

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Migrations
      # Lint and autocorrect deprecated IconButton
      class IconButtonComponent < RuboCop::Cop::Cop
        INVALID_MESSAGE = <<~STR
          `Primer::IconButton` is deprecated. Please use `Primer::Beta::IconButton` instead.
        STR

        def_node_matcher :icon_button, <<~PATTERN
          (send $(const (const nil? :Primer) :IconButton) :new ...)
        PATTERN

        def_node_matcher :hash_with_box_value?, <<~PATTERN
          (hash ... (pair (sym :box) (...)) ... )
        PATTERN

        def on_send(node)
          return unless icon_button(node)

          add_offense(node, message: INVALID_MESSAGE)
        end

        def autocorrect(node)
          return if hash_with_box_value?(node.arguments.first)

          lambda do |corrector|
            corrector.replace(icon_button(node), "Primer::Beta::IconButton")
          end
        end
      end
    end
  end
  end

Version data entries

114 entries across 114 versions & 2 rubygems

Version Path
primer_view_components-0.30.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.39.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.39.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.38.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
primer_view_components-0.29.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
primer_view_components-0.28.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.37.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.37.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.36.2 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.36.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.36.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
primer_view_components-0.27.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.35.2 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.35.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb
primer_view_components-0.26.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.35.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
primer_view_components-0.26.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.34.0 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.33.2 lib/primer/view_components/linters/migrations/iconbutton_component.rb
openproject-primer_view_components-0.33.1 lib/primer/view_components/linters/migrations/iconbutton_component.rb