Skip to content

Commit

Permalink
FactoryBot/AttributeDefinedStatically. Optimize #on_block callback
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Jun 28, 2020
1 parent fad3387 commit d893a35
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -31,12 +31,15 @@ class AttributeDefinedStatically < Cop
(send _ !#reserved_method? $...)
PATTERN

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

def on_block(node)
factory_attributes(node).to_a.flatten.each do |attribute|
attributes = factory_attributes(node) || []
attributes = [attributes] if !attributes.is_a?(Array)

attributes.each do |attribute|
next unless offensive_receiver?(attribute.receiver, node)
next if proc?(attribute) || association?(attribute.first_argument)

Expand Down

0 comments on commit d893a35

Please sign in to comment.