Class: RuboCop::Cop::FactoryBot::ExcessiveCreateList
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::FactoryBot::ExcessiveCreateList
- Includes:
- ConfigurableExplicitOnly
- Defined in:
- lib/rubocop/cop/factory_bot/excessive_create_list.rb
Overview
Check for excessive model creation in a list.
Constant Summary collapse
- MESSAGE =
'Avoid using `create_list` with more than %<max_amount>s items.'
- RESTRICT_ON_SEND =
%i[create_list].freeze
Constants included from FactoryBot::Language
Instance Method Summary collapse
Methods included from ConfigurableExplicitOnly
#explicit_only?, #factory_call?
Methods included from FactoryBot::Language
Instance Method Details
#create_list?(node) ⇒ Object
33 34 35 |
# File 'lib/rubocop/cop/factory_bot/excessive_create_list.rb', line 33 def_node_matcher :create_list?, <<~PATTERN (send #factory_call? :create_list {sym str} $(int _) ...) PATTERN |
#on_send(node) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubocop/cop/factory_bot/excessive_create_list.rb', line 39 def on_send(node) number_node = create_list?(node) return unless number_node max_amount = cop_config['MaxAmount'] return if number_node.value <= max_amount add_offense(number_node, message: format(MESSAGE, max_amount: max_amount)) end |