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 in Style/RedundantEach with block-pass arguments #11137

Closed
Darhazer opened this issue Nov 1, 2022 · 1 comment · Fixed by #11138
Closed

False positive in Style/RedundantEach with block-pass arguments #11137

Darhazer opened this issue Nov 1, 2022 · 1 comment · Fixed by #11138
Labels

Comments

@Darhazer
Copy link
Member

Darhazer commented Nov 1, 2022

Given the code:

records.each(&:lock!).each do |record|
end

Style/RedundantEach says "Remove redundant each" on the first each.

Note that this passes the cop:

records.each { |record| record.lock! }.each do |record|
end

So it's only when there is a block-pass that it ignores that there is an actual block implementation.


Expected behavior

No offences

Actual behavior

test.rb:2:8: C: [Corrected] Style/RedundantEach: Remove redundant each.
records.each(&:lock!).each do |record|
       ^^^^^

It's gets corrected to:

records(&:lock!).each do |record|
end

RuboCop version

rubocop -V
1.38.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [arm64-darwin21]
@Mangara
Copy link
Contributor

Mangara commented Nov 1, 2022

I noticed the same with two symbols: threads.each(&:kill).each(&:join), so the last doesn't need to be a block.

ydah added a commit to ydah/rubocop that referenced this issue Nov 3, 2022
…en using `each` with a symbol proc argument

Fix: rubocop#11137
koic added a commit that referenced this issue Nov 3, 2022
[Fix #11137] Fix a false positive for `Style/RedundantEach` when using `each` with a symbol proc argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants