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

Autofix might result to invalid code when RaiseArgs EnforcedStyle is set to compact #9303

Closed
jlahtinen opened this issue Dec 29, 2020 · 0 comments · Fixed by #9306
Closed
Labels

Comments

@jlahtinen
Copy link

Testfiles

$ more .* *

::::::::::::::
.rubocop.yml
::::::::::::::

Style/RaiseArgs:
  EnforcedStyle: compact

::::::::::::::
foo.rb
::::::::::::::

# frozen_string_literal: true

# Class to demonstrate RaiseArgs EnforcedStyle
class Foo
  def a
    bar
  rescue NonBarException
    raise BarError.new, 'bar'
  end
end

Running autofix

$ rubocop -a

Inspecting 1 file
C

Offenses:

foo.rb:8:5: C: [Corrected] Style/RaiseArgs: Provide an exception object as an argument to raise.
    raise BarError.new, 'bar'
    ^^^^^^^^^^^^^^^^^^^^^^^^^
foo.rb:8:10: C: [Corrected] Layout/SpaceAroundMethodCallOperator: Avoid using spaces around a method call operator.
    raise .new('bar')
         ^

1 file inspected, 2 offenses detected, 2 offenses corrected

Expected result vs actual fix

diff --git a/foo.rb b/foo.rb
index fea592f..b8ceecd 100644
--- a/foo.rb
+++ b/foo.rb
@@ -5,6 +5,6 @@ class Foo
   def a
     bar
   rescue NonBarException
-    raise BarError.new 'bar'
+    raise.new('bar')
   end
 end
@koic koic added the bug label Dec 29, 2020
koic added a commit to koic/rubocop that referenced this issue Dec 29, 2020
Fixes rubocop#9303.

This PR fixes an incorrect auto-correct for `Style/RaiseArgs` with
`EnforcedStyle: compact` when using exception instantiation argument.
koic added a commit that referenced this issue Dec 30, 2020
…e_args

[Fix #9303] Fix an incorrect auto-correct for `Style/RaiseArgs`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants