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

False positive for Lint/RedundantWithIndex when calling with_index without each beforehand #12769

Closed
Earlopain opened this issue Mar 10, 2024 · 0 comments · Fixed by #12790
Closed
Labels

Comments

@Earlopain
Copy link
Contributor

This cop is marked as safe, however some code can result in offenses that when autocorrected break the code.


Expected behavior

No offense for the following:

ary = [1, 2, 3, 4].each
ary.with_index { |v| v }

Actual behavior

Autocorrection to the following:

ary = [1,2,3,4].each
ary { |v| v }

This will raise when executed: undefined method `ary'. It will also promt Lint/UselessAssignment on the first line since that variable is now unused.

RuboCop version

$ [bundle exec] rubocop -V
1.62.0 (using Parser 3.3.0.4, rubocop-ast 1.31.1, running on ruby 3.3.0) [x86_64-linux]
  - rubocop-performance 1.20.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.27.1
@koic koic added the bug label Mar 13, 2024
koic added a commit to koic/rubocop that referenced this issue Mar 13, 2024
Fixes rubocop#12769.

This PR fixes a false positive for `Lint/RedundantWithIndex`
when calling `with_index` with receiver with a block.
koic added a commit to koic/rubocop that referenced this issue Mar 13, 2024
Fixes rubocop#12769.

This PR fixes a false positive for `Lint/RedundantWithIndex`
when calling `with_index` with receiver and a block.
koic added a commit that referenced this issue Mar 14, 2024
…undant_with_index

[Fix #12769] Fix a false positive for `Lint/RedundantWithIndex`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants