Navigation Menu

Skip to content
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

Style/IdenticalConditionalBranches should be marked as unsafe #9980

Closed
Drowze opened this issue Aug 4, 2021 · 1 comment · Fixed by #9982
Closed

Style/IdenticalConditionalBranches should be marked as unsafe #9980

Drowze opened this issue Aug 4, 2021 · 1 comment · Fixed by #9982
Labels

Comments

@Drowze
Copy link
Contributor

Drowze commented Aug 4, 2021

Expected behavior

I expect safe autocorrection not to break my existing ruby code.

Actual behavior

Running a cop marked as safe breaks my existing ruby code.

Steps to reproduce the problem

Given test.rb

x = 0

if x == 0
  x += 1
  puts "if"
else
  x += 1
  puts "else"
end

# output when executed:
# if

When I run rubocop -a --only Style/IdenticalConditionalBranches, it autocorrects my file to:

x = 0

x += 1
if x == 0
  puts "if"
else
  puts "else"
end

# output when executed:
# else

RuboCop version

$ rubocop -V
1.18.4 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 2.7.3 x86_64-darwin20)
Drowze added a commit to Drowze/rubocop that referenced this issue Aug 4, 2021
@koic koic added the bug label Aug 4, 2021
@koic
Copy link
Member

koic commented Aug 4, 2021

This is a false positive bug because this cop can safe detect the offense.

koic added a commit to koic/rubocop that referenced this issue Aug 5, 2021
…alBranches`

Fixes rubocop#9980.

This PR fixes a false positive for `Style/IdenticalConditionalBranches`
when assigning to a variable used in a condition.
bbatsov pushed a commit that referenced this issue Aug 12, 2021
…hes`

Fixes #9980.

This PR fixes a false positive for `Style/IdenticalConditionalBranches`
when assigning to a variable used in a condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants