-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #12370] Make Style/HashEachMethods
aware of unused block value
#12398
[Fix #12370] Make Style/HashEachMethods
aware of unused block value
#12398
Conversation
5ac7cac
to
23a6ba2
Compare
@@ -47,6 +47,40 @@ | |||
RUBY | |||
end | |||
|
|||
it 'does not register an offense when the value and value block arguments of `Enumerable#each` method are unused' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value and value -> key are value
unused -> used
expect_no_offenses('foo.each { |k, v| do_something(k, v) }') | ||
end | ||
|
||
it 'does not register an offense when the single block argument of `Enumerable#each` method are unused' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused -> used
expect_no_offenses('foo.each { |e| do_something(e) }') | ||
end | ||
|
||
it 'does not register an offense when the parenthesized value and value block arguments of `Enumerable#each` method are unused' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused -> used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value and value -> key and value
expect_no_offenses('foo.each { |(k, v)| do_something(e) }') | ||
end | ||
|
||
it 'registers an offense when the value block argument of `Enumerable#each` method are unused' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are -> is
RUBY | ||
end | ||
|
||
it 'registers an offense when the key block argument of `Enumerable#each` method are unused' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are -> is
23a6ba2
to
7813213
Compare
# | ||
# # bad | ||
# hash.values.each { |v| p v } | ||
# hash.each.each { |unused_key, v| p v } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be just hash.each
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I've fixed it.
…k value Fixes rubocop#12370. This PR makes `Style/HashEachMethods` aware of unused block value. And this PR suppresses the following new offense in this repository: ```console $ bundle exec rubocop --only Style/HashEachMethods -A (snip) Offenses: lib/rubocop/cop/style/bisected_attr_accessor.rb:36:11: C: [Corrected] Style/HashEachMethods: Use each_value instead of each, and remove the unused _visibility block argument. find_macros(class_node.body).each do |_visibility, macros| ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1519 files inspected, 1 offense detected, 1 offense corrected ```
7813213
to
b42f1a0
Compare
Fixes #12370.
This PR makes
Style/HashEachMethods
aware of unused block value. And this PR suppresses the following new offense in this repository:Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.