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

Performance/Sample cop incorrectly reports and auto-corrects var.shuffle.join #1816

Closed
DMA57361 opened this issue Apr 21, 2015 · 3 comments · Fixed by #1817
Closed

Performance/Sample cop incorrectly reports and auto-corrects var.shuffle.join #1816

DMA57361 opened this issue Apr 21, 2015 · 3 comments · Fixed by #1817

Comments

@DMA57361
Copy link

After updating to 0.30.1 we've had the following new offence come up, which I believe is incorrect and causes a change in behaviour when auto-correcting:

Performance/Sample: Use sample instead of shuffle.join

When auto-correcting, this changes variable.shuffle.join into variable.sample.
This behaviour is very different:

2.2.0 :001 > ('A'..'Z').to_a.shuffle.join
 => "HKUFLXGYBTNVQMRZCJEIPSOWDA"
2.2.0 :002 > ('A'..'Z').to_a.sample
 => "M"
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 21, 2015

Definitely a bug.

aaw added a commit to aaw/aptible-tasks that referenced this issue Apr 21, 2015
The most recent sweetness build just picked up a bug in the Performance/Sample
cop (rubocop/rubocop#1816) from 0.30.1, which fails
the sweetness build. Let's pin rubocop to a known good version so that we're
not continually picking up new cops and changes from patch versions without
explicit updates to aptible-tasks.
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 21, 2015

//cc @rrosenblum

@rrosenblum
Copy link
Contributor

Yes, this is a bug. I apologize, I was missing adequate negative test cases during the last change. I think that I can get a fix together quickly.

Thank you for submitting the issue.

rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Apr 21, 2015
bbatsov added a commit that referenced this issue Apr 21, 2015
[Fix #1816] Do not register an offense for shuffle when using all of the elements of the shuffled array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants