@@ -41,6 +41,11 @@ class AroundBlock < Base
4141 (numblock (send nil? :around sym ?) ...)
4242 PATTERN
4343
44+ # @!method hook_itblock(node)
45+ def_node_matcher :hook_itblock , <<~PATTERN
46+ (itblock (send nil? :around sym ?) ...)
47+ PATTERN
48+
4449 # @!method find_arg_usage(node)
4550 def_node_search :find_arg_usage , <<~PATTERN
4651 {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
@@ -51,14 +56,20 @@ def on_block(node)
5156 if example_proxy . nil?
5257 add_no_arg_offense ( node )
5358 else
54- check_for_unused_proxy ( node , example_proxy )
59+ check_for_unused_proxy ( node , example_proxy , example_proxy . name )
5560 end
5661 end
5762 end
5863
5964 def on_numblock ( node )
6065 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 )
6273 end
6374 end
6475
@@ -68,25 +79,14 @@ def add_no_arg_offense(node)
6879 add_offense ( node , message : MSG_NO_ARG )
6980 end
7081
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 )
8383 find_arg_usage ( block ) do |usage |
84- return if usage . include? ( s ( :lvar , :_1 ) )
84+ return if usage . include? ( s ( :lvar , name ) )
8585 end
8686
8787 add_offense (
88- block . children . last ,
89- message : format ( MSG_UNUSED_ARG , arg : :_1 )
88+ range ,
89+ message : format ( MSG_UNUSED_ARG , arg : name )
9090 )
9191 end
9292 end
0 commit comments