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
Auto-correction for Style/IdenticalConditionalBranches cop breaks behavior #10858
Comments
You're seeing offenses after autocorrection because the cop is leaving the However, the autocorrection is faulty too, because as you pointed out it changes the implicit return value:
will never return the |
Now that autocorrection has been added, I'm running into an edge case. If an empty # frozen_string_literal: true
if foo
else
end Running # frozen_string_literal: true
end It seems that the combination of the Happy to open a separate issue if that's better. Footnotes
|
Can confirm, than in rubocop |
Hey @fatkodima, @koic! The error described in original issue still occurs in |
Ah, I see. I assumed it is working now (from the mentioned comment) and only the problem with correction exists. |
@DmitryBarskov You're right. I've reopen this issue. |
Description: suggested auto-correction for
Style/IdenticalConditionalBranches
offence breaks anif
statement if it is the last statement in the method with no explicitreturn
keyword.Expected behavior
Rubocop does not suggest auto-correction for
Style/IdenticalConditionalBranches
rule.Actual behavior
Rubocop suggests an auto-correction which breaks the last
if
statement in a method.Running with options
rubocop test.rb --debug --cache false
Steps to reproduce the problem
Given a plain Ruby file
test.rb
:Run it:
ruby test.rb
. It exits with code 0.Run
rubocop
on it:rubocop test.rb -A
.It changes the
#test
method to:Run the script again:
ruby test.rb
.I still expect the script to exit with code 0.
Actual exit code of auto-corrected script is 1.
RuboCop version
Rubocop 1.32.0 (fresh version) with no extensions.
The text was updated successfully, but these errors were encountered: