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
Fixesrubocop#7712.
This PR fixes an incorrect autocorrect for `Style/OrAssignment`
when using `elsif` branch.
The following is a reproduction procedure.
```ruby
% cat example.rb
foo = if foo
foo
elsif
bar
else
'default'
end
```
It is changed to the code with syntax error as follows.
```console
% bundle exec rubocop -a --only Style/OrAssignment
(snip)
% cat example.rb
foo ||= elsif
bar
else
'default'
% ruby -c example.rb
example.rb:1: syntax error, unexpected `elsif'
foo ||= elsif
```
The or assignment operator replaced when using `elsif` branch is complicated.
The PR will accept the above case without offense.
Fixes#7712.
This PR fixes an incorrect autocorrect for `Style/OrAssignment`
when using `elsif` branch.
The following is a reproduction procedure.
```ruby
% cat example.rb
foo = if foo
foo
elsif
bar
else
'default'
end
```
It is changed to the code with syntax error as follows.
```console
% bundle exec rubocop -a --only Style/OrAssignment
(snip)
% cat example.rb
foo ||= elsif
bar
else
'default'
% ruby -c example.rb
example.rb:1: syntax error, unexpected `elsif'
foo ||= elsif
```
The or assignment operator replaced when using `elsif` branch is complicated.
The PR will accept the above case without offense.
Expected behavior
Using the
--safe
flag should mean syntax errors aren't introduced into code.Actual behavior
Using
rubocop -a --safe --only "Style/OrAssignment"
introduces a syntax errorSteps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: