Sha256: 2c8a3e86bb764a966773f4ff5178804663ec54e969d5b08311db2876efcba03d

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 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 EnforcedStyle:
      #   # 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.'

        # @!method bad_method?(node)
        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

4 entries across 4 versions & 1 rubygems

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