Sha256: 840acab52c81aca1d622e7786c032f01efcafc8629ed9e924d08601e58ca60ad

Contents?: true

Size: 959 Bytes

Versions: 14

Compression:

Stored size: 959 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 `%<klass>s`.'

        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))
        end

        def autocorrect(node)
          return false if target_ruby_version <= 2.3

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

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.72.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.71.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.70.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.69.0 lib/rubocop/cop/lint/unified_integer.rb