Skip to content

Commit c51c544

Browse files
authored
Merge pull request #949 from andrykonchin/optimize-performance-attribute_defined_statically
Performance. FactoryBot/AttributeDefinedStatically
2 parents 87229cc + 97f1b58 commit c51c544

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ class AttributeDefinedStatically < Cop
3131
(send _ !#reserved_method? $...)
3232
PATTERN
3333

34-
def_node_search :factory_attributes, <<-PATTERN
34+
def_node_matcher :factory_attributes, <<-PATTERN
3535
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
3636
PATTERN
3737

3838
def on_block(node)
39-
factory_attributes(node).to_a.flatten.each do |attribute|
39+
attributes = factory_attributes(node) || []
40+
attributes = [attributes] unless attributes.is_a?(Array)
41+
42+
attributes.each do |attribute|
4043
next unless offensive_receiver?(attribute.receiver, node)
4144
next if proc?(attribute) || association?(attribute.first_argument)
4245

0 commit comments

Comments
 (0)