Skip to content

Commit 0647c04

Browse files
marcandremergify[bot]
authored andcommitted
AbcSize calculator: visit children first
1 parent 05cc149 commit 0647c04

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/rubocop/cop/metrics/utils/abc_size_calculator.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def initialize(node)
4242
end
4343

4444
def calculate
45-
46-
@node.each_node do |child|
45+
visit_depth_last(@node) do |child|
4746
calculate_node(child)
4847
end
4948

@@ -75,6 +74,11 @@ def else_branch?(node)
7574

7675
private
7776

77+
def visit_depth_last(node, &block)
78+
node.each_child_node { |child| visit_depth_last(child, &block) }
79+
yield node
80+
end
81+
7882
def calculate_node(node)
7983
@assignment += 1 if assignment?(node)
8084

0 commit comments

Comments
 (0)