Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow up faker-ruby/faker#2613 (comment). Fixes #11165. This PR fixes a false positive for `Style/RedundantEach` when any method is used between methods containing `each` in the method name. That method in between may convert from `Enumerator` to `Array`. e.g. `map(&:do_something)` ```ruby 'string'.each_char.class # => Enumerator 'string'.each_char.map(&:to_i).class # => Array ``` `each_with_index` is a method of `Array`, not of `Enumerator`. ```ruby 'string'.each_char.map(&:to_i).respond_to?(:each_with_index) # => true 'string'.each_char.map(&:to_i).respond_to?(:with_index) # => false ``` Therefore, it allows any method to be used between methods containing `each` to prevent `NoMethodError`.
- Loading branch information
Showing
3 changed files
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#11165](https://github.com/rubocop/rubocop/issues/11165): Fix a false positive for `Style/RedundantEach` when any method is used between methods containing `each` in the method name. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters