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
The Style/MultilineWhenThen cop should remove then statements from all mulitline case statements w/o creating invalid ruby code.
Actual behavior
If RuboCop encounters a case statement that uses then and {}s it will just remove the then statements, which results in invalid ruby:
Steps to reproduce the problem
Run rubocop --only Style/MultilineWhenThen on the following code:
caseversion.to_s# to_s to make sure someone didn't pass us an intwhen'9.0'then{'ActiveDirectory'=>'Veeam Explorer for Microsoft Active Directory','SQL'=>'Veeam Explorer for Microsoft SQL Server','Exchange'=>'Veeam Explorer for Microsoft Exchange','SharePoint'=>'Veeam Explorer for Microsoft SharePoint','Oracle'=>'Veeam Explorer for Oracle'}end
This will autocorrect to:
caseversion.to_s# to_s to make sure someone didn't pass us an intwhen'9.0'{'ActiveDirectory'=>'Veeam Explorer for Microsoft Active Directory','SQL'=>'Veeam Explorer for Microsoft SQL Server','Exchange'=>'Veeam Explorer for Microsoft Exchange','SharePoint'=>'Veeam Explorer for Microsoft SharePoint','Oracle'=>'Veeam Explorer for Oracle'}end
RuboCop version
0.78.0
The text was updated successfully, but these errors were encountered:
…henThen`
Fixesrubocop#7616.
This PR fixes an incorrect autocorrect for `Style/MultilineWhenThen`
for when statement with then is an array or a hash.
The following is a reproduction procedure.
```console
% cat example.rb
case condition
when foo then {
key: 'value'
}
end
% ruby -c example.rb
Syntax OK
```
It is changed to the code with syntax error as follows.
```console
% bundle exec rubocop -a --only Style/MultilineWhenThen
(snip)
% cat example.rb
case condition
when foo {
key: 'value'
}
end
% ruby -c example.rb
example.rb:3: syntax error, unexpected ':', expecting '}'
key: 'value'
example.rb:4: syntax error, unexpected '}', expecting end-of-input
```
The same is true when replacing a hash with an array.
The PR will accept these cases without offense.
Expected behavior
The Style/MultilineWhenThen cop should remove then statements from all mulitline case statements w/o creating invalid ruby code.
Actual behavior
If RuboCop encounters a case statement that uses then and {}s it will just remove the then statements, which results in invalid ruby:
Steps to reproduce the problem
Run
rubocop --only Style/MultilineWhenThen
on the following code:This will autocorrect to:
RuboCop version
The text was updated successfully, but these errors were encountered: