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/RedundantBegin auto correct on empty rescue with trailing comment results in invalid syntax #1964

Closed
DMA57361 opened this issue Jun 10, 2015 · 1 comment
Assignees
Labels

Comments

@DMA57361
Copy link

When auto correcting this:

def method
  begin
    do_some_stuff
  rescue # rubocop:disable Lint/RescueException
  end
end

Rubocop produces the following output:

Offenses:

rbfail_repro.rb:2:3: C: [Corrected] Style/RedundantBegin: Redundant begin block detected.
  begin
  ^^^^^
rbfail_repro.rb:3:8: E: unexpected token kEND
rescue end
       ^^^
rbfail_repro.rb:4:10: W: Unnecessary disabling of Lint/RescueException.
  rescue # rubocop:disable Lint/RescueException
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

And the file is left looking like this, which as you can see is not valid:

def method
  do_some_stuff
rescue end

Extra notes

  • It's failed for me when trying random trailing comments, not just the rubocop:disable (that's just how I came across the error in our code. )
  • It will also break if there's a => e (or equivalent) after the rescue (assuming there's a trailing comment afterwards)

It does work if there's any content in the rescue (with or without the comment) and when there's no comment present.

@jonas054 jonas054 added the bug label Jun 13, 2015
@jonas054 jonas054 self-assigned this Jun 13, 2015
@jonas054
Copy link
Collaborator

Confirmed as a bug. I'll try to fix it.

bbatsov added a commit that referenced this issue Jun 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants