Skip to content

Commit

Permalink
Merge pull request #9985 from koic/mark_unsafe_autocorrect_for_style_…
Browse files Browse the repository at this point in the history
…identical_conditional_branches

Mark `Style/IdenticalConditionalBranches` as unsafe auto-correction
  • Loading branch information
koic committed Aug 7, 2021
2 parents d572439 + 6059c6d commit 37134fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
@@ -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

0 comments on commit 37134fb

Please sign in to comment.