Sha256: 01d94c3ab57049fadc857e7afe2c8d740bbd0ae75cb5147ceb89b601fc2b5107

Contents?: true

Size: 837 Bytes

Versions: 6

Compression:

Stored size: 837 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.'.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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.49.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.49.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.48.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.48.0 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.47.1 lib/rubocop/cop/lint/float_out_of_range.rb
rubocop-0.47.0 lib/rubocop/cop/lint/float_out_of_range.rb