Sha256: 17f4938874179317448f1243d407f797fbb4efc162345c4dc8bcbdbe5784b81b

Contents?: true

Size: 1.18 KB

Versions: 46

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # `BigDecimal.new()` is deprecated since BigDecimal 1.3.3.
      # This cop identifies places where `BigDecimal.new()`
      # can be replaced by `BigDecimal()`.
      #
      # @example
      #   # bad
      #   BigDecimal.new(123.456, 3)
      #
      #   # good
      #   BigDecimal(123.456, 3)
      #
      class BigDecimalNew < Cop
        MSG = '`%<double_colon>sBigDecimal.new()` is deprecated. ' \
              'Use `%<double_colon>sBigDecimal()` instead.'

        def_node_matcher :big_decimal_new, <<~PATTERN
          (send
            (const ${nil? cbase} :BigDecimal) :new ...)
        PATTERN

        def on_send(node)
          return unless big_decimal_new(node) do |captured_value|
            double_colon = captured_value ? '::' : ''
            message = format(MSG, double_colon: double_colon)

            add_offense(node, location: :selector, message: message)
          end
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(node.loc.selector)
            corrector.remove(node.loc.dot)
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 35 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.88.0 lib/rubocop/cop/lint/big_decimal_new.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.87.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.87.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.86.0 lib/rubocop/cop/lint/big_decimal_new.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/big_decimal_new.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/big_decimal_new.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.85.1 lib/rubocop/cop/lint/big_decimal_new.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.85.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.84.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.83.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.82.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.81.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.80.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-0.80.0 lib/rubocop/cop/lint/big_decimal_new.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/big_decimal_new.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/big_decimal_new.rb