Skip to content

Commit c3921c0

Browse files
authored
Merge pull request #12636 from Earlopain/fix-error-for-style-hash-each-methods
Fix an error for `Style/HashEachMethods` when a block with both parameters has no body
2 parents 54c3f61 + 17f5fcf commit c3921c0

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#12636](https://github.com/rubocop/rubocop/pull/12636): Fix an error for `Style/HashEachMethods` when a block with both parameters has no body. ([@earlopain][])

lib/rubocop/cop/style/hash_each_methods.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def on_block(node)
7171

7272
# rubocop:disable Metrics/AbcSize
7373
def check_unused_block_args(node, key, value)
74+
return if node.body.nil?
75+
7476
value_unused = unused_block_arg_exist?(node, value)
7577
key_unused = unused_block_arg_exist?(node, key)
7678
return if value_unused && key_unused

spec/rubocop/cop/style/hash_each_methods_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
expect_no_offenses('foo.each { |k, v| do_something }')
110110
end
111111

112+
it 'does not register an offense when the body of `Enumerable#each` is empty' do
113+
expect_no_offenses('foo.each { |k, v| }')
114+
end
115+
112116
it 'registers an offense when the rest value block argument of `Enumerable#each` method is unused' do
113117
expect_offense(<<~RUBY)
114118
foo.each { |k, *v| do_something(*v) }

0 commit comments

Comments
 (0)