Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance. FactoryBot/AttributeDefinedStatically #949

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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] unless attributes.is_a?(Array)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think these two lines could be written a bit simpler:

attributes = Array(factory_attributes(node))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already suggested this, but unfortunately, node deconstructs itself in this case
#949 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for clarifying.


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

Expand Down