Sha256: cd5b59c0822e79f3bf45c08f080dc5d3eade78ecb078730955360eba76e223c9

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 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 = '`BigDecimal.new()` is deprecated. Use `BigDecimal()` 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 |cbase|
            add_offense(node.loc.selector) do |corrector|
              corrector.remove(node.loc.selector)
              corrector.remove(node.loc.dot)
              corrector.remove(cbase) if cbase
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.69.2 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.69.1 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.69.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.68.0 lib/rubocop/cop/lint/big_decimal_new.rb
rubocop-1.67.0 lib/rubocop/cop/lint/big_decimal_new.rb