Sha256: dcc42e37a2aa7aceeace2bc0d52193f9ea992b0924fb54779dc21430d9b45a99

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Solidus
      # This cop finds icon helper calls and suggest using solidus_icon
      #
      # @example EnforcedStyle:
      #   # bad
      #   helper.icon('example')
      #
      #   # good
      #   helper.solidus_icon('example')
      #
      #
      class SpreeIconDeprecated < Base
        extend AutoCorrector
        include TargetSolidusVersion
        minimum_solidus_version 2.3

        MSG = 'In Solidus 2.3, `icon` helper has been deprecated in favor of `solidus_icon`'

        RESTRICT_ON_SEND = %i[icon].freeze

        def_node_matcher :icon?, <<~PATTERN
          (send (send nil? ...) :icon ...)
        PATTERN

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

          add_offense(node) do |corrector|
            corrector.replace(node, node.source.gsub('icon', 'solidus_icon'))
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-solidus-0.1.3 lib/rubocop/cop/solidus/spree_icon_deprecated.rb
rubocop-solidus-0.1.2 lib/rubocop/cop/solidus/spree_icon_deprecated.rb
rubocop-solidus-0.1.1 lib/rubocop/cop/solidus/spree_icon_deprecated.rb
rubocop-solidus-0.1.0 lib/rubocop/cop/solidus/spree_icon_deprecated.rb