Sha256: 4dba7a0862a844ea0e8f4d1008094e14bbbd4788e6bfe8c075d8fcfc97e8461f

Contents?: true

Size: 772 Bytes

Versions: 54

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop identifies Float literals which are, like, really really really
      # really really really really really big. Too big. No-one needs Floats
      # that big. If you need a float that big, something is wrong with you.
      #
      # @example
      #
      #   # bad
      #
      #   float = 3.0e400
      #
      # @example
      #
      #   # good
      #
      #   float = 42.9
      class FloatOutOfRange < Cop
        MSG = 'Float out of range.'

        def on_float(node)
          value, = *node

          return unless value.infinite? ||
                        value.zero? && node.source =~ /[1-9]/

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

54 entries across 35 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/float_out_of_range.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/float_out_of_range.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.85.1 lib/rubocop/cop/lint/float_out_of_range.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.85.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.84.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.83.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.82.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.81.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.80.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.80.0 lib/rubocop/cop/lint/float_out_of_range.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/float_out_of_range.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.79.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.78.0 lib/rubocop/cop/lint/float_out_of_range.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/float_out_of_range.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/float_out_of_range.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/float_out_of_range.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/float_out_of_range.rb