-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
In spec we had the following code
invoices = [FactoryBot.create(:invoice, customer_unit_id: @user.current_unit.id),
FactoryBot.create(:invoice, supplier_unit_id: @user.current_unit.id),]
user = FactoryBot.create(:user)During work to enable Lint/UselessAssignment. Rubocop found that invoices was an unused variable. I ran be rubocop path.rb --only Lint/UselessAssignment -A and it replaced the code with the following code. which is fine. Lint/UselessAssignment is unsafe autocorrect so I ran it with -A.
[FactoryBot.create(:invoice, customer_unit_id: @user.current_unit.id),
FactoryBot.create(:invoice, supplier_unit_id: @user.current_unit.id),]
user = FactoryBot.create(:user)When I lint this code I get errors from Lint/Void. Running autofix safe version (-a) rubocop removed the array definition, so my two invoices are not created any more.
user = FactoryBot.create(:user)Expected behavior
My suggestion is to don't modify the array if it has anything which could have side effect
Actual behavior
Removes by factory bot calls
Steps to reproduce the problem
Explained above
RuboCop version
⋊> ~/d/w/d/f/repo on st-bugsnag-w40 ⨯ bundle exec rubocop -V 12:57:13
1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.1) [arm64-darwin22]
- rubocop-capybara 2.19.0
- rubocop-factory_bot 2.24.0
- rubocop-performance 1.19.1
- rubocop-rails 2.22.1
- rubocop-rspec 2.25.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels