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/TrailingUnderscoreVariable should give the user a valid recommendation. #2660

Closed
envygeeks opened this issue Jan 18, 2016 · 4 comments
Closed

Comments

@envygeeks
Copy link

At this time doing _, e, _ will result in a violation of the aforementioned cop without guiding them to doing Ruby the right way... as in: _, e,, this could be because of something else but ultimately normally we do the latter rather than the former, but recently did the former and it triggered that error and confused even me for a second while I was trying to figure out what it was on about.

@alexdowad
Copy link
Contributor

Sorry, @envygeeks, can you please post a snippet of valid Ruby code which can be used to reproduce the problem? It would also be helpful if you can show both 1) what the current output of RC is and 2) what you suggest it should be.

@envygeeks
Copy link
Author

class MyClass
  def initialize
    @a, _, _, _ = test
  end

  def test
    %W(
      shit just got real
    )
  end
end
test.rb:4:9: C: Do not use trailing _s in parallel assignment.
    @a, _, _, _ = test
        ^^^^^^^

The error gives no hint that @a, = test is the better way. I think the error would be better as:

test.rb:4:9: C: Do not use trailing _s in parallel assignment, prefer `_, var, = blah`
    @a, _, _, _ = test
        ^^^^^^^

@envygeeks
Copy link
Author

Actually, I don't care what improvement is made (probably) as long as it's not so vague.

@alexdowad
Copy link
Contributor

prefer _, var, = blah

Agreed, but better still, it should use the name of the actual variable from the code here rather than var.

@bbatsov bbatsov closed this as completed in c3e6b12 Feb 9, 2016
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

No branches or pull requests

2 participants