Sha256: ca863d0f15298628e65c316c9536c32d4d960cd7ab58f95423e8d8aaf28e4cea

Contents?: true

Size: 905 Bytes

Versions: 14

Compression:

Stored size: 905 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)
          lambda do |corrector|
            corrector.replace(node.loc.name, 'Integer')
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/unified_integer.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.87.1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.87.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.86.0 lib/rubocop/cop/lint/unified_integer.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/unified_integer.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/unified_integer.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.85.1 lib/rubocop/cop/lint/unified_integer.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.85.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.84.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.83.0 lib/rubocop/cop/lint/unified_integer.rb
rubocop-0.82.0 lib/rubocop/cop/lint/unified_integer.rb