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 #7831

Closed
dteoh opened this issue Mar 31, 2020 · 0 comments · Fixed by #7832
Closed

False positive in Style/HashEachMethods #7831

dteoh opened this issue Mar 31, 2020 · 0 comments · Fixed by #7832
Labels

Comments

@dteoh
Copy link

dteoh commented Mar 31, 2020

I have code like this:

def validate_values
  # values is a Hash
  values.each do |key, value|
    next if value.is_a? String

    errors.add :values, :unsupported, key: key
  end
end

Expected behavior

No error is raised by Style/HashEachMethods.

Actual behavior

 C: Style/HashEachMethods: Use each_value instead of values.each.
    values.each do |key, value|
    ^^^^^^^^^^^

Steps to reproduce the problem

Run RuboCop on the code snippet.

RuboCop version

⟩ bundle exec rubocop -V
0.80.1 (using Parser 2.7.0.5, running on ruby 2.5.5 x86_64-darwin19)
@koic koic added the bug label Mar 31, 2020
koic added a commit to koic/rubocop that referenced this issue Mar 31, 2020
Fixes rubocop#7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
koic added a commit to koic/rubocop that referenced this issue Mar 31, 2020
koic added a commit to koic/rubocop that referenced this issue Mar 31, 2020
Fixes rubocop#7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
koic added a commit to koic/rubocop that referenced this issue Mar 31, 2020
Fixes rubocop#7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
bbatsov pushed a commit that referenced this issue Mar 31, 2020
Fixes #7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
saurabhmaurya15 pushed a commit to saurabhmaurya15/rubocop that referenced this issue Apr 7, 2020
Fixes rubocop#7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Apr 28, 2020
Fixes rubocop#7831.

This PR fix a false positive for `Style/HashEachMethods` when there is no
receiver for `keys` and `values`.

The following is an examples.

```ruby
values.each { |k, v| do_something(k, v) }
keys.each { |k, v| do_something(k, v) }
```

False negatives occur in cases such as object that inherit Hash,
but that is perhaps a corner case.
I think it is more worthwhile to resolve the false positives with
common naming of `values`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants