@@ -39,9 +39,6 @@ class UnexpectedBlockArity < Base
39
39
def on_block ( node )
40
40
return if acceptable? ( node )
41
41
42
- # If there is a splat argument, then the arity is fine
43
- return true if node . arguments . any? ( &:restarg_type? )
44
-
45
42
expected = expected_arity ( node . method_name )
46
43
actual = arg_count ( node )
47
44
return if actual >= expected
@@ -50,17 +47,7 @@ def on_block(node)
50
47
add_offense ( node , message : message )
51
48
end
52
49
53
- def on_numblock ( node )
54
- return if acceptable? ( node )
55
-
56
- expected = expected_arity ( node . method_name )
57
- actual = node . children [ 1 ] # the maximum numbered param for the block
58
-
59
- return if actual >= expected
60
-
61
- message = format ( MSG , method : node . method_name , expected : expected , actual : actual )
62
- add_offense ( node , message : message )
63
- end
50
+ alias on_numblock on_block
64
51
65
52
private
66
53
@@ -81,10 +68,16 @@ def expected_arity(method)
81
68
end
82
69
83
70
def arg_count ( node )
71
+ return node . children [ 1 ] if node . numblock_type? # the maximum numbered param for the block
72
+
84
73
# Only `arg`, `optarg` and `mlhs` (destructuring) count as arguments that
85
74
# can be used. Keyword arguments are not used for these methods so are
86
75
# ignored.
87
- node . arguments . count { |arg | arg . arg_type? || arg . optarg_type? || arg . mlhs_type? }
76
+ node . arguments . count do |arg |
77
+ return Float ::INFINITY if arg . restarg_type?
78
+
79
+ arg . arg_type? || arg . optarg_type? || arg . mlhs_type?
80
+ end
88
81
end
89
82
end
90
83
end
0 commit comments