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 wrong suggestion with array variables #10754

Closed
j-seixas opened this issue Jun 27, 2022 · 1 comment · Fixed by #10758
Closed

Style/HashExcept wrong suggestion with array variables #10754

j-seixas opened this issue Jun 27, 2022 · 1 comment · Fixed by #10758
Labels

Comments

@j-seixas
Copy link

@j-seixas j-seixas commented Jun 27, 2022

When using reject with an array variable to exclude keys from hash, the suggestion is wrong.


Expected behavior

some_var = [:foo, :baz]
{foo: 1, bar: 2, baz: 3}.reject { |k, _v| k.include?(some_var) }

Expected message:

Use `except(*some_var)` instead. (convention:Style/HashExcept)

Actual behavior

Use `except(some_var)` instead. (convention:Style/HashExcept)

Steps to reproduce the problem

some_var = [:foo, :baz]
{foo: 1, bar: 2, baz: 3}.reject { |k, _v| k.include?(some_var) }
# {bar: 2}

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

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

RuboCop version

$ bundle exec rubocop -V
1.31.0 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.1.0 x86_64-darwin20)
  - rubocop-graphql 0.14.3
  - rubocop-performance 1.14.2
  - rubocop-rails 2.15.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.11.1
@j-seixas
Copy link
Author

@j-seixas j-seixas commented Jun 27, 2022

related PR #10699

@koic koic added the bug label Jun 28, 2022
koic added a commit to koic/rubocop that referenced this issue Jun 28, 2022
Fixes rubocop#10754.

This PR fixes an incorrect autocorrect for `Style/HashExcept`
when using a non-literal collection receiver for `include?`.
bbatsov pushed a commit that referenced this issue Jun 28, 2022
Fixes #10754.

This PR fixes an incorrect autocorrect for `Style/HashExcept`
when using a non-literal collection receiver for `include?`.
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