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

Style/HashExcept: Nonequivalent suggestion when using the second, value param of a reject block #10843

Closed
theblang opened this issue Jul 28, 2022 · 0 comments · Fixed by #10844
Labels

Comments

@theblang
Copy link

The Style/HashExcept rule wants to turn:

{ foo: 1, bar: 2, baz: 3 }.reject { |_, v| [1, 2].include?(v) }

into the nonequivalent

{ foo: 1, bar: 2, baz: 3 }.except(1, 2)


Expected behavior

Perhaps nothing, since we're using the second, value param of the reject block. All of the examples show using the first, key param.

Actual behavior

rubocop and rubocop -a want to suggest { foo: 1, bar: 2, baz: 3 }.except(1, 2)

Steps to reproduce the problem

  • Paste the code: { foo: 1, bar: 2, baz: 3 }.reject { |_, v| [1, 2].include?(v) }
  • Run rubocop -a
  • See the code changed to: { foo: 1, bar: 2, baz: 3 }.except(1, 2)

RuboCop version

1.32.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 3.1.2 x86_64-linux-musl)

@koic koic added the bug label Jul 29, 2022
koic added a commit to koic/rubocop that referenced this issue Jul 29, 2022
Fixes rubocop#10843.

This PR fix a false positive for `Style/HashExcept` when using
`reject` and calling `include?` method with symbol array and
second block value.
koic added a commit that referenced this issue Jul 30, 2022
…sh_except

[Fix #10843] Fix a false positive for `Style/HashExcept`
WJWH pushed a commit to WJWH/rubocop that referenced this issue Aug 8, 2022
Fixes rubocop#10843.

This PR fix a false positive for `Style/HashExcept` when using
`reject` and calling `include?` method with symbol array and
second block value.
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