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/RaiseArgs autocorrection produces syntactically invalid Ruby code. #6748

Closed
patbl opened this issue Feb 9, 2019 · 1 comment
Closed
Assignees
Labels

Comments

@patbl
Copy link

patbl commented Feb 9, 2019

Expected behavior

Style/RaiseArgs autocorrection produces syntactically valid Ruby code.

Actual behavior

Style/RaiseArgs autocorrection produces syntactically invalid Ruby code.

Steps to reproduce the problem

[23:00:21] ~/Documents  ➜ cat lol.rb
false || raise(RuntimeError.new('lol'))
[23:00:48] ~/Documents  ➜ rubocop --only Style/RaiseArgs --auto-correct lol.rb
Inspecting 1 file
E

Offenses:

lol.rb:1:10: C: [Corrected] Style/RaiseArgs: Provide an exception class and message as arguments to raise.
false || raise(RuntimeError.new('lol'))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lol.rb:1:16: E: Lint/Syntax: unexpected token tCONSTANT
(Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
false || raise RuntimeError, 'lol'
               ^^^^^^^^^^^^
lol.rb:1:35: E: Lint/Syntax: unexpected token tNL
(Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
false || raise RuntimeError, 'lol' ...


1 file inspected, 3 offenses detected, 1 offense corrected
[23:00:57] ~/Documents  ➜ ruby -c lol.rb
lol.rb:1: syntax error, unexpected tCONSTANT, expecting do or '{' or '('
false || raise RuntimeError, 'lol'
lol.rb:1: syntax error, unexpected '\n', expecting '.' or &. or :: or '['

RuboCop version

[22:59:48] ~/Documents  ➜ rubocop -V
0.63.1 (using Parser 2.5.3.0, running on ruby 2.6.0 x86_64-darwin17)
@koic koic added the bug label Feb 9, 2019
@Drenmi Drenmi self-assigned this Feb 11, 2019
@Drenmi
Copy link
Collaborator

Drenmi commented Feb 11, 2019

Thanks for the report @patbl! I have opened a PR with a fix in #6758. The fix will be shipped as part of a bugfix release sometime within the next couple weeks.

@koic koic closed this as completed in 9c9e116 Feb 11, 2019
koic added a commit that referenced this issue Feb 11, 2019
[Fix #6748] Fix Style/RaiseArgs auto-correction breaking in contexts that require parentheses
@Drenmi Drenmi mentioned this issue Feb 19, 2019
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

3 participants