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

Fix Style/RedundantEach for non-chained each_ calls #11142

Merged
merged 1 commit into from Nov 3, 2022

Conversation

fatkodima
Copy link
Contributor

Style/RedundantEach fails for [1, 2, 3].each with no method block_type? for nil.

And incorrectly detects as offense the following:

build_enumerator(outer: [[1, 2, 3].each]).each

@RDeckard
Copy link
Contributor

RDeckard commented Nov 2, 2022

Great, thanks! 🙏

And moreover, shouldn't the documentation be corrected this way:

This cop is unsafe, as it can produce false positives if the receiver is not an Enumerable Enumerator.

Because for example an array, which is an Enumerable but not an Enumerator, does not implement #with_object or #with_index.

@koic koic merged commit 0829626 into rubocop:master Nov 3, 2022
@koic
Copy link
Member

koic commented Nov 3, 2022

Thanks!

koic added a commit that referenced this pull request Nov 3, 2022
Follow up of #11142 (comment).

```console
% ruby -e 'p [].each.class'
Enumerator
```
@koic
Copy link
Member

koic commented Nov 3, 2022

@RDeckard Good catch. I've fixed that typo in the master.

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 this pull request may close these issues.

None yet

3 participants