Skip to content

Commit 61bd21a

Browse files
committed
Use Node#any_block_type?
Follow up rubocop/rubocop-ast#356.
1 parent 79be0f2 commit 61bd21a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/rubocop/cop/performance/chain_array_allocation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ChainArrayAllocation < Base
5454
def_node_matcher :chain_array_allocation?, <<~PATTERN
5555
(send {
5656
(send _ $%RETURN_NEW_ARRAY_WHEN_ARGS {int lvar ivar cvar gvar send})
57-
({block numblock} (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
57+
(any_block (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
5858
(send _ $%RETURNS_NEW_ARRAY ...)
5959
} $%HAS_MUTATION_ALTERNATIVE ...)
6060
PATTERN
@@ -75,7 +75,7 @@ def on_send(node)
7575
def enumerable_select_method?(node)
7676
# NOTE: `QueryMethods#select` in Rails accepts positional arguments, whereas `Enumerable#select` does not.
7777
# This difference can be utilized to reduce the knowledge requirements related to `select`.
78-
(node.block_type? || node.numblock_type?) && node.send_node.arguments.empty?
78+
node.any_block_type? && node.send_node.arguments.empty?
7979
end
8080
end
8181
end

lib/rubocop/cop/performance/times_map.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class TimesMap < Base
3636
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'
3737
RESTRICT_ON_SEND = %i[map collect].freeze
3838

39+
def_node_matcher :times_map_call, <<~PATTERN
40+
{
41+
(any_block $(call (call $!nil? :times) {:map :collect}) ...)
42+
$(call (call $!nil? :times) {:map :collect} (block_pass ...))
43+
}
44+
PATTERN
45+
3946
def on_send(node)
4047
check(node)
4148
end
@@ -75,13 +82,6 @@ def message(map_or_collect, count)
7582
end
7683
format(template, count: count.source, map_or_collect: map_or_collect.method_name)
7784
end
78-
79-
def_node_matcher :times_map_call, <<~PATTERN
80-
{
81-
({block numblock} $(call (call $!nil? :times) {:map :collect}) ...)
82-
$(call (call $!nil? :times) {:map :collect} (block_pass ...))
83-
}
84-
PATTERN
8585
end
8686
end
8787
end

rubocop-performance.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ Gem::Specification.new do |s|
3131
}
3232

3333
s.add_dependency('rubocop', '>= 1.48.1', '< 2.0')
34-
s.add_dependency('rubocop-ast', '>= 1.31.1', '< 2.0')
34+
s.add_dependency('rubocop-ast', '>= 1.38.0', '< 2.0')
3535
end

0 commit comments

Comments
 (0)