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

Bug with parallel assignment auto-correct #1873

Closed
infertux opened this issue May 7, 2015 · 7 comments · Fixed by #1875
Closed

Bug with parallel assignment auto-correct #1873

infertux opened this issue May 7, 2015 · 7 comments · Fixed by #1875

Comments

@infertux
Copy link

infertux commented May 7, 2015

See #1831, the auto-correct function is broken with this edge case:

-        best_separator, best_score = separator, score if score > best_score
+        best_separator = separator
+        best_score = score if score > best_score

Both assignments should stay conditional.

As a side note, I don't get why this cop is in the Performance category - does it have any performance implications? Shouldn't it be in Style?

@bbatsov
Copy link
Collaborator

bbatsov commented May 7, 2015

Shouldn't it be in Style?

It should be. I totally missed this.

@infertux
Copy link
Author

infertux commented May 7, 2015

Actually, I just came across https://github.com/JuanitoFatas/fast-ruby#parallel-assignment-vs-sequential-assignment-code - so I guess Performance makes sense too 😄.

@bbatsov
Copy link
Collaborator

bbatsov commented May 7, 2015

While this is true, the bigger value is the improved readability of the code, so I still think this should be a style cop.

@bbatsov
Copy link
Collaborator

bbatsov commented May 7, 2015

//cc @rrosenblum

@infertux
Copy link
Author

infertux commented May 7, 2015

Agreed.

@rrosenblum
Copy link
Contributor

Thank you for the bug report. I agree, this is a bug. I will start working on a fix for it soon.

As for Performance vs Style, it falls into both categories. It was brought up as an old feature request and in talking about performance cops. When we are talking about the ability to assign variables in the millions per second, doubling the performance is negligible except in extreme cases. I agree that the bigger gain is readability, therefore making this better suited as a Style Cop. I will also go ahead and make this change.

rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 7, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 10, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 10, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 11, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 11, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 11, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 11, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 11, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 13, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 13, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 15, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 15, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 15, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue May 15, 2015
@infertux
Copy link
Author

Good stuff @rrosenblum 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants