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

False positive in Style/HashEachMethods #9839

Closed
styx opened this issue May 31, 2021 · 1 comment · Fixed by #9840
Closed

False positive in Style/HashEachMethods #9839

styx opened this issue May 31, 2021 · 1 comment · Fixed by #9840

Comments

@styx
Copy link

styx commented May 31, 2021

I have code like this:

        ::ApplicationRecord.connection.execute(sql).values.each do |field|
          p field
        end

Expected behavior

No error is raised by Style/HashEachMethods. There is no such method each_value as it's not a Hash.

Actual behavior

dates.rb:56:59: C: [Correctable] Style/HashEachMethods: Use each_value instead of values.each.
        ::ApplicationRecord.connection.execute(build_sql).values.each do |field|

Steps to reproduce the problem

Run RuboCop on the code snippet.

RuboCop version

$ [bundle exec] rubocop -V
1.15.0 (using Parser 3.0.1.1, rubocop-ast 1.6.0, running on ruby 3.0.1 x86_64-linux)
  - rubocop-rails 2.9.1
@koic
Copy link
Member

koic commented May 31, 2021

Style/HashEachMethods cop is already marked as unsafe. I've open #9840 that can use AllowedReceivers to rule out false positives.

koic added a commit to koic/rubocop that referenced this issue May 31, 2021
…ethods`

Fixes rubocop#9839.

This PR adds `AllowedReceivers` option for `Style/HashEachMethods`.

`Style/HashEachMethods` cop is already marked as unsafe.
This PR can use allow list to rule out false positives.
bbatsov pushed a commit that referenced this issue May 31, 2021
Fixes #9839.

This PR adds `AllowedReceivers` option for `Style/HashEachMethods`.

`Style/HashEachMethods` cop is already marked as unsafe.
This PR can use allow list to rule out false positives.
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 a pull request may close this issue.

2 participants