Class: RuboCop::Cop::Perx::RedundantFactoryBot
- Inherits:
-
Cop
- Object
- Cop
- RuboCop::Cop::Perx::RedundantFactoryBot
- Defined in:
- lib/perx/rubocop/custom_linters/redundant_factory_bot.rb
Constant Summary collapse
- MSG =
'Exclude FactoryBot classname when creating/building records'
- FACTORY_BOT_METHODS =
%i[create build build_stubbed].freeze
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
18 19 20 21 22 |
# File 'lib/perx/rubocop/custom_linters/redundant_factory_bot.rb', line 18 def autocorrect(node) lambda do |corrector| corrector.remove_leading(node.source_range, 'FactoryBot.'.length) end end |
#on_block(node) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/perx/rubocop/custom_linters/redundant_factory_bot.rb', line 10 def on_block(node) node.each_descendant(:send) do |send_node| next unless factory_bot_invoked?(send_node.children[0]) && record_built_or_created?(send_node.children[1]) add_offense(send_node, location: :expression) end end |