Sha256: 223a0b3f8c90e527e7ed34c6a7794efa8e5bfd1ac7a95991f0325bd0d04e7f05

Contents?: true

Size: 902 Bytes

Versions: 6

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for using Fixnum or Bignum constant.
      #
      # @example
      #
      #   # bad
      #
      #   1.is_a?(Fixnum)
      #   1.is_a?(Bignum)
      #
      # @example
      #
      #   # good
      #
      #   1.is_a?(Integer)
      class UnifiedInteger < Cop
        MSG = 'Use `Integer` instead of `%s`.'.freeze

        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, :expression, format(MSG, klass))
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node.loc.name, 'Integer')
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.49.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.49.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.48.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.48.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.47.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.47.0 lib/rubocop/cop/lint/unified_integer.rb