False positive of Style/IdenticalConditionalBranches
when conditional mutates duplicate line
#12249
Labels
Style/IdenticalConditionalBranches
when conditional mutates duplicate line
#12249
Expected behavior
When the conditional mutates the variable used in the duplication, the conditional should not be considered a violation of cop
Style/IdenticalConditionalBranches
.Actual behavior
This is identified as a duplicate branch, but because the duplicated line's behavior is modified by the conditional, it should not be caught by the cop, similar to #9982 where the conditional checks
x == 0
beforex += 1
.Steps to reproduce the problem
Extracted from Bundler, this removes a leading
-
and performs a different action depending on if the-
existed.The unsafe auto-correct is as follows, which is wrong:
The version I ended up with that avoids this issue is in this PR.
RuboCop version
1.56.3
The text was updated successfully, but these errors were encountered: