Skip to content

Commit c61929a

Browse files
committed
Use case instead of if
It reads nicer, and `flog` agrees. Before: ❯ flog lib/rubocop/cop/rspec/mixin/top_level_group.rb 29.7: flog total 5.0: flog/method average 9.8: RuboCop::Cop::RSpec::TopLevelGroup#top_level_nodes lib/rubocop/cop/rspec/mixin/top_level_group.rb:36-44 7.6: RuboCop::Cop::RSpec::TopLevelGroup#on_new_investigation lib/rubocop/cop/rspec/mixin/top_level_group.rb:10-16 4.9: RuboCop::Cop::RSpec::TopLevelGroup#top_level_groups lib/rubocop/cop/rspec/mixin/top_level_group.rb:20-22 After: ❯ flog lib/rubocop/cop/rspec/mixin/top_level_group.rb 25.8: flog total 4.3: flog/method average 7.2: RuboCop::Cop::RSpec::TopLevelGroup#top_level_nodes lib/rubocop/cop/rspec/mixin/top_level_group.rb:35-44 6.3: RuboCop::Cop::RSpec::TopLevelGroup#on_new_investigation lib/rubocop/cop/rspec/mixin/top_level_group.rb:10-15 4.9: RuboCop::Cop::RSpec::TopLevelGroup#top_level_groups lib/rubocop/cop/rspec/mixin/top_level_group.rb:19-21
1 parent 9a5d604 commit c61929a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/rubocop/cop/rspec/mixin/top_level_group.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module TopLevelGroup
99

1010
def on_new_investigation
1111
super
12-
return unless root_node
1312

1413
top_level_groups.each do |node|
1514
on_top_level_example_group(node) if example_group?(node)
@@ -34,11 +33,12 @@ def top_level_group?(node)
3433
end
3534

3635
def top_level_nodes(node)
37-
if node.nil?
38-
[]
39-
elsif node.begin_type?
36+
return [] if node.nil?
37+
38+
case node.type
39+
when :begin
4040
node.children
41-
elsif node.module_type? || node.class_type?
41+
when :module, :class
4242
top_level_nodes(node.body)
4343
else
4444
[node]

0 commit comments

Comments
 (0)