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

Incorrect substitution for Style/HashExcept #10031

Closed
tobyaw opened this issue Aug 23, 2021 · 0 comments · Fixed by #10032
Closed

Incorrect substitution for Style/HashExcept #10031

tobyaw opened this issue Aug 23, 2021 · 0 comments · Fixed by #10032
Labels

Comments

@tobyaw
Copy link

tobyaw commented Aug 23, 2021

I have code:

{}.reject { |_k, v| v.count.eql? 1 }

and the Style/HashExcept rule changes this to invalid and non-equivalent code:

{}.except(v.count)

Expected behavior

The Style/HashExcept rule should not trigger.

Actual behavior

% rubocop --debug
For /Users/tobyaw/Desktop/test: configuration from /Users/tobyaw/Desktop/test/.rubocop.yml
Default configuration from /usr/local/lib/ruby/gems/3.0.0/gems/rubocop-1.19.1/config/default.yml
Use parallel by default.
Running parallel inspection
Inspecting 1 file
Scanning /Users/tobyaw/Desktop/test/test.rb
Loading cache from /Users/tobyaw/.cache/rubocop_cache/05049447917d12ccd9963972b8d2f31cd20e5928/6d7a3b621ca1730e04accd938619e4bdab66cfb1/c47fd0571652f491f0955dba32cb5933e95d6a5f
C

Offenses:

test.rb:4:4: C: [Correctable] Style/HashExcept: Use except(v.count) instead.
{}.reject { |_k, v| v.count.eql? 1 }
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable
Finished in 0.19939299998804927 seconds

Steps to reproduce the problem

Sample code:

#!/usr/bin/env ruby
# frozen_string_literal: true

{}.reject { |_k, v| v.count.eql? 1 }

Rubocop config:

AllCops:
  TargetRubyVersion: 3.0
  NewCops: enable

RuboCop version

% rubocop -V
1.19.1 (using Parser 3.0.2.0, rubocop-ast 1.10.0, running on ruby 3.0.2 x86_64-darwin20)
koic added a commit to koic/rubocop that referenced this issue Aug 24, 2021
Fixes rubocop#10031.

This PR fixes a false positive for `Style/HashExcept`
when comparing with hash value.
bbatsov pushed a commit that referenced this issue Aug 24, 2021
Fixes #10031.

This PR fixes a false positive for `Style/HashExcept`
when comparing with hash 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