Sha256: cb066896ff7e7361210d19455aa7a06e5233b83e993f41c78b28b52ea4d70ade

Contents?: true

Size: 1.21 KB

Versions: 225

Compression:

Stored size: 1.21 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 < Base
        extend AutoCorrector

        MSG = '`%<double_colon>sBigDecimal.new()` is deprecated. ' \
              'Use `%<double_colon>sBigDecimal()` instead.'
        RESTRICT_ON_SEND = %i[new].freeze

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

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

            add_offense(node.loc.selector, message: message) do |corrector|
              corrector.remove(node.loc.selector)
              corrector.remove(node.loc.dot)
            end
          end
        end
      end
    end
  end
end

Version data entries

225 entries across 216 versions & 21 rubygems

Version Path
rubocop-1.66.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.66.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.65.1 lib/rubocop/cop/lint/big_decimal_new.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.65.0 lib/rubocop/cop/lint/big_decimal_new.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/big_decimal_new.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/big_decimal_new.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/lint/big_decimal_new.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.64.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.63.4 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.63.3 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.63.2 lib/rubocop/cop/lint/big_decimal_new.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.63.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.63.0 lib/rubocop/cop/lint/big_decimal_new.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.62.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.62.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.61.0 lib/rubocop/cop/lint/big_decimal_new.rb