Class: RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically
- Inherits:
-
Cop
- Object
- WorkaroundCop
- Cop
- RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically
- Defined in:
- lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb
Overview
Always declare attribute values as blocks.
Constant Summary collapse
- MSG =
'Use a block to declare attribute values.'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb', line 47 def autocorrect(node) if node.parenthesized? autocorrect_replacing_parens(node) else autocorrect_without_parens(node) end end |
#on_block(node) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb', line 38 def on_block(node) factory_attributes(node).to_a.flatten.each do |attribute| next unless offensive_receiver?(attribute.receiver, node) next if proc?(attribute) || association?(attribute) add_offense(attribute, location: :expression) end end |