Sha256: 1f1a3a6a8b82649b0c47c0b809f02534effa4f4adeefa928b6f090bbee857b4d

Contents?: true

Size: 922 Bytes

Versions: 9

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Checks for using Fixnum or Bignum constant.
      #
      # @example
      #
      #   # bad
      #   1.is_a?(Fixnum)
      #   1.is_a?(Bignum)
      #
      #   # good
      #   1.is_a?(Integer)
      class UnifiedInteger < Base
        extend AutoCorrector

        MSG = 'Use `Integer` instead of `%<klass>s`.'

        # @!method fixnum_or_bignum_const(node)
        def_node_matcher :fixnum_or_bignum_const, <<~PATTERN
          (:const {nil? (:cbase)} ${:Fixnum :Bignum})
        PATTERN

        def on_const(node)
          klass = fixnum_or_bignum_const(node)

          return unless klass

          add_offense(node, message: format(MSG, klass: klass)) do |corrector|
            next if target_ruby_version <= 2.3

            corrector.replace(node.loc.name, 'Integer')
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.69.2 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.69.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.69.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.68.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.67.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.66.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.66.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-1.65.1 lib/rubocop/cop/lint/unified_integer.rb