Sha256: fdc08a67494dfccbfd044545a93e944839bf9ebd06fea8bd596a9b4b020355ae

Contents?: true

Size: 777 Bytes

Versions: 6

Compression:

Stored size: 777 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? && /[1-9]/.match?(node.source)

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/float_out_of_range.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.87.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.87.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.86.0 lib/rubocop/cop/lint/float_out_of_range.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/float_out_of_range.rb