forked from rubocop/rubocop-minitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refute_instance_of.rb
41 lines (37 loc) · 1.07 KB
/
refute_instance_of.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
40
41
# frozen_string_literal: true
module RuboCop
module Cop
module Minitest
# Enforces the use of `refute_instance_of(Class, object)`
# over `refute(object.instance_of?(Class))`.
#
# @example
# # bad
# refute(object.instance_of?(Class))
# refute(object.instance_of?(Class), 'message')
#
# # bad
# refute_equal(Class, object.class)
# refute_equal(Class, object.class, 'message')
#
# # good
# refute_instance_of(Class, object)
# refute_instance_of(Class, object, 'message')
#
class RefuteInstanceOf < Base
include InstanceOfAssertionHandleable
extend AutoCorrector
RESTRICT_ON_SEND = %i[refute refute_equal].freeze
def_node_matcher :instance_of_assertion?, <<~PATTERN
{
(send nil? :refute (send $_ :instance_of? $const) $_?)
(send nil? :refute_equal $const (send $_ :class) $_?)
}
PATTERN
def on_send(node)
investigate(node, :refute)
end
end
end
end
end