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

Mark Style/IdenticalConditionalBranches as unsafe auto-correction #9985

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#9985](https://github.com/rubocop/rubocop/pull/9985): Mark `Style/IdenticalConditionalBranches` as unsafe auto-correction. ([@koic][])
3 changes: 2 additions & 1 deletion config/default.yml
Expand Up @@ -3604,8 +3604,9 @@ Style/IdenticalConditionalBranches:
line at the end of each branch, which can validly be moved
out of the conditional.
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.36'
VersionChanged: '1.16'
VersionChanged: '<<next>>'

Style/IfInsideElse:
Description: 'Finds if nodes inside else, which can be converted to elsif.'
Expand Down
16 changes: 16 additions & 0 deletions lib/rubocop/cop/style/identical_conditional_branches.rb
Expand Up @@ -7,6 +7,22 @@ module Style
# each branch of a conditional expression. Such expressions should normally
# be placed outside the conditional expression - before or after it.
#
# This cop is marked unsafe auto-correction as the order of method invocations
# must be guaranteed in the following case:
#
# [source,ruby]
# ----
# if method_that_modifies_global_state # 1
# method_that_relies_on_global_state # 2
# foo # 3
# else
# method_that_relies_on_global_state # 2
# bar # 3
# end
# ----
#
# In such a case, auto-correction may change the invocation order.
#
# NOTE: The cop is poorly named and some people might think that it actually
# checks for duplicated conditional branches. The name will probably be changed
# in a future major RuboCop release.
Expand Down