Skip to content

Commit

Permalink
[Fix #9350] Wrap in parens before replacing unless with if and !
Browse files Browse the repository at this point in the history
  • Loading branch information
magneland authored and bbatsov committed Jan 9, 2021
1 parent d197cc4 commit ad71469
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_wrap_in_parens_before_replacing_unless.md
@@ -0,0 +1 @@
* [#9350](https://github.com/rubocop-hq/rubocop/pull/9350): Wrap in parens before replacing `unless` with `if` and `!`. ([@magneland][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/sole_nested_conditional.rb
Expand Up @@ -63,13 +63,13 @@ def offending_branch?(branch)
end

def autocorrect(corrector, node, if_branch)
corrector.wrap(node.condition, '(', ')') if node.condition.or_type?

if node.unless?
corrector.replace(node.loc.keyword, 'if')
corrector.insert_before(node.condition, '!')
end

corrector.wrap(node.condition, '(', ')') if node.condition.or_type?

and_operator = if_branch.unless? ? ' && !' : ' && '
if if_branch.modifier_form?
correct_for_guard_condition_style(corrector, node, if_branch, and_operator)
Expand Down

0 comments on commit ad71469

Please sign in to comment.