Sha256: 948d28fb8eb23e2e90677026e5ca2a78c3a495f34f82411ec68b1d019ab2a2f0

Contents?: true

Size: 788 Bytes

Versions: 11

Compression:

Stored size: 788 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
      #
      #   # good
      #   float = 42.9
      class FloatOutOfRange < Cop
        MSG = 'Float out of range.'.freeze

        def on_float(node)
          value, = *node
          if value.infinite?
            add_offense(node, :expression, MSG)
          elsif value.zero? && node.source =~ /[1-9]/
            add_offense(node, :expression, MSG)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.46.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.45.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.44.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.44.0 lib/rubocop/cop/lint/float_out_of_range.rb