Class: RuboCop::Cop::Lint::NegativeP

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/lint/negative_p.rb,
lib/rubocop/cop/lint/negative_p/version.rb

Overview

This cop checks for method call Numeric#negative?

Examples:

# bad
42.negative?

# good
42 >= 0

Constant Summary collapse

MSG =
"Do not use Numeric#negative?"
VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.support_target_ruby_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rubocop/cop/lint/negative_p.rb', line 22

def self.support_target_ruby_version?(version)
  version < 2.3
end

Instance Method Details

#on_send(node) ⇒ Object



26
27
28
29
30
# File 'lib/rubocop/cop/lint/negative_p.rb', line 26

def on_send(node)
  return unless negative?(node)

  add_offense(node)
end