forked from rubocop/rubocop-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inquiry.rb
39 lines (36 loc) · 953 Bytes
/
inquiry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# This cop checks that Active Support's `inquiry` method is not used.
#
# @example
# # 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'
#
class Inquiry < Base
MSG = "Prefer Ruby's comparison operators over Active Support's `inquiry`."
RESTRICT_ON_SEND = %i[inquiry].freeze
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
end
end
end
end