Skip to content

Commit 9b39a55

Browse files
authored
Merge pull request #12773 from Earlopain/fix-error-for-style-for
Fix an error for `Style/For` with `EnforcedStyle: for` when no receiver
2 parents 409c5a0 + 54dbee1 commit 9b39a55

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#12773](https://github.com/rubocop/rubocop/pull/12773): Fix an error for `Style/For` with `EnforcedStyle: for` when no receiver. ([@earlopain][])

lib/rubocop/cop/style/for.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def on_block(node)
6666
return unless suspect_enumerable?(node)
6767

6868
if style == :for
69+
return unless node.receiver
70+
6971
add_offense(node, message: PREFER_FOR) do |corrector|
7072
EachToForCorrector.new(node).call(corrector)
7173
opposite_style_detected

spec/rubocop/cop/style/for_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,14 @@ def func
488488
RUBY
489489
end
490490

491+
it 'registers no offense when there is no receiver' do
492+
expect_no_offenses(<<~RUBY)
493+
each do |n|
494+
puts n
495+
end
496+
RUBY
497+
end
498+
491499
it 'registers multiple offenses' do
492500
expect_offense(<<~RUBY)
493501
for n in [1, 2, 3] do

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy