Sha256: fb9db95af3e941a329a2e79c4e0cdaf0da15cb27a17a866cbfaa5d6e7115f17d

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Solidus
      # This cop finds user.default_credit_card suggest using user.wallet.default_wallet_payment_source.
      #
      # @example
      #
      #   # bad
      #   user.default_credit_card
      #
      #   # good
      #   user.wallet.default_wallet_payment_source
      #
      class SpreeDefaultCreditCardDeprecated < Base
        extend AutoCorrector
        include TargetSolidusVersion
        minimum_solidus_version 2.2

        MSG = 'user.default_credit_card is deprecated. Please use user.wallet.default_wallet_payment_source instead.'

        def_node_matcher :default_credit_card?, <<~PATTERN
          (send ... :default_credit_card)
        PATTERN

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

          add_offense(node) do |corrector|
            corrector.replace(node, node.source.gsub('default_credit_card', 'wallet.default_wallet_payment_source'))
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-solidus-0.2.0 lib/rubocop/cop/solidus/spree_default_credit_card_deprecated.rb
rubocop-solidus-0.1.4 lib/rubocop/cop/solidus/spree_default_credit_card_deprecated.rb