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

RaiseArgs shouldn't autocorrect 3-arg form #4723

Closed
ptarjan opened this issue Sep 11, 2017 · 0 comments · May be fixed by LemonSpike/Xcodeproj#4
Closed

RaiseArgs shouldn't autocorrect 3-arg form #4723

ptarjan opened this issue Sep 11, 2017 · 0 comments · May be fixed by LemonSpike/Xcodeproj#4

Comments

@ptarjan
Copy link
Contributor

ptarjan commented Sep 11, 2017


Expected behavior

$ cat /tmp/a.rb
begin
  1 / 0
rescue => e
  raise StandardError, 'hi', e.backtrace
end
$ ruby /tmp/a.rb
/tmp/a.rb:2:in `/': hi (StandardError)
	from /tmp/a.rb:2:in `<main>'
$ cat .rubocop.yml
RaiseArgs:
  EnforcedStyle: compact

No autocorrect. Or if you want to get fancy you can autocorrect to

$ cat /tmp/a.rb
begin
  1 / 0
rescue => e
  new_e = StandardError.new('hi')
  new_e.set_backtrace(e.backtrace)
  raise new_e
end

Actual behavior

$ rubocop -a a.rb
Inspecting 1 file
C

Offenses:

a.rb:4:3: C: [Corrected] Provide an exception object as an argument to raise.
  raise StandardError, 'hi', e.backtrace
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
$ cat /tmp/a.rb
begin
  1 / 0
rescue => e
  raise StandardError.new('hi', e.backtrace)
end
$ ruby /tmp/a.rb
/tmp/a.rb:4:in `initialize': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
	from /tmp/a.rb:4:in `new'
	from /tmp/a.rb:4:in `rescue in <main>'
	from /tmp/a.rb:1:in `<main>'

Steps to reproduce the problem

See above

RuboCop version

$ rubocop -V
0.49.1 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin16)
smakagon added a commit to smakagon/rubocop that referenced this issue Sep 13, 2017

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
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.

1 participant