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

Lint/Void and Lint/UselessAssignment removed my code with side effect #12377

Closed
stoivo opened this issue Nov 9, 2023 · 0 comments · Fixed by #12384
Closed

Lint/Void and Lint/UselessAssignment removed my code with side effect #12377

stoivo opened this issue Nov 9, 2023 · 0 comments · Fixed by #12384

Comments

@stoivo
Copy link
Contributor

stoivo commented Nov 9, 2023

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
koic added a commit to koic/rubocop that referenced this issue Nov 15, 2023
Fixes rubocop#12377.

This PR fixes false positives for `Lint/Void` when
a collection literal that includes non-literal elements in a method definition.
koic added a commit that referenced this issue Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant