You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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
The text was updated successfully, but these errors were encountered:
Fixesrubocop#9303.
This PR fixes an incorrect auto-correct for `Style/RaiseArgs` with
`EnforcedStyle: compact` when using exception instantiation argument.
Testfiles
$ more .* *
::::::::::::::
.rubocop.yml
::::::::::::::
::::::::::::::
foo.rb
::::::::::::::
Running autofix
$ rubocop -a
Expected result vs actual fix
The text was updated successfully, but these errors were encountered: