@@ -41,6 +41,11 @@ class AroundBlock < Base
41
41
(numblock (send nil? :around sym ?) ...)
42
42
PATTERN
43
43
44
+ # @!method hook_itblock(node)
45
+ def_node_matcher :hook_itblock , <<~PATTERN
46
+ (itblock (send nil? :around sym ?) ...)
47
+ PATTERN
48
+
44
49
# @!method find_arg_usage(node)
45
50
def_node_search :find_arg_usage , <<~PATTERN
46
51
{(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
@@ -51,14 +56,20 @@ def on_block(node)
51
56
if example_proxy . nil?
52
57
add_no_arg_offense ( node )
53
58
else
54
- check_for_unused_proxy ( node , example_proxy )
59
+ check_for_unused_proxy ( node , example_proxy , example_proxy . name )
55
60
end
56
61
end
57
62
end
58
63
59
64
def on_numblock ( node )
60
65
hook_numblock ( node ) do
61
- check_for_numblock ( node )
66
+ check_for_unused_proxy ( node , node . children . last , :_1 )
67
+ end
68
+ end
69
+
70
+ def on_itblock ( node )
71
+ hook_itblock ( node ) do
72
+ check_for_unused_proxy ( node , node . children . last , :it )
62
73
end
63
74
end
64
75
@@ -68,25 +79,14 @@ def add_no_arg_offense(node)
68
79
add_offense ( node , message : MSG_NO_ARG )
69
80
end
70
81
71
- def check_for_unused_proxy ( block , proxy )
72
- find_arg_usage ( block ) do |usage |
73
- return if usage . include? ( s ( :lvar , proxy . name ) )
74
- end
75
-
76
- add_offense (
77
- proxy ,
78
- message : format ( MSG_UNUSED_ARG , arg : proxy . name )
79
- )
80
- end
81
-
82
- def check_for_numblock ( block )
82
+ def check_for_unused_proxy ( block , range , name )
83
83
find_arg_usage ( block ) do |usage |
84
- return if usage . include? ( s ( :lvar , :_1 ) )
84
+ return if usage . include? ( s ( :lvar , name ) )
85
85
end
86
86
87
87
add_offense (
88
- block . children . last ,
89
- message : format ( MSG_UNUSED_ARG , arg : :_1 )
88
+ range ,
89
+ message : format ( MSG_UNUSED_ARG , arg : name )
90
90
)
91
91
end
92
92
end
0 commit comments