Class: RuboCop::Cop::Rails::Inquiry

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rails/inquiry.rb

Overview

Checks that Active Support’s ‘inquiry` method is not used.

Examples:

# bad - String#inquiry
ruby = 'two'.inquiry
ruby.two?

# good
ruby = 'two'
ruby == 'two'

# bad - Array#inquiry
pets = %w(cat dog).inquiry
pets.gopher?

# good
pets = %w(cat dog)
pets.include? 'cat'

Constant Summary collapse

MSG =
"Prefer Ruby's comparison operators over Active Support's `inquiry`."
RESTRICT_ON_SEND =
%i[inquiry].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



29
30
31
32
33
34
35
# File 'lib/rubocop/cop/rails/inquiry.rb', line 29

def on_send(node)
  return unless node.arguments.empty?
  return unless (receiver = node.receiver)
  return if !receiver.str_type? && !receiver.array_type?

  add_offense(node.loc.selector)
end