Skip to content

Commit

Permalink
[Fix rubocop#8497] Fix Style/IfUnlessModifier to handle if-end condit…
Browse files Browse the repository at this point in the history
…ion in method argument list
  • Loading branch information
Dmytro Savochkin committed Aug 9, 2020
1 parent 1a4e748 commit 7ad850b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
* [#8480](https://github.com/rubocop-hq/rubocop/issues/8480): Tweak callback list of `Lint/MissingSuper`. ([@marcandre][])
* [#8481](https://github.com/rubocop-hq/rubocop/pull/8481): Fix autocorrect for elements with newlines in `Style/SymbolArray` and `Style/WordArray`. ([@biinari][])
* [#8475](https://github.com/rubocop-hq/rubocop/issues/8475): Fix a false positive for `Style/HashAsLastArrayItem` when there are duplicate hashes in the array. ([@wcmonty][])
* [#8497](https://github.com/rubocop-hq/rubocop/issues/8497): Fix `Style/IfUnlessModifier` to add parentheses when converting if-end condition inside a parenthesized method argument list. ([@dsavochkin][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/statement_modifier.rb
Expand Up @@ -72,7 +72,7 @@ def parenthesize?(node)
return true if parent.assignment? || parent.operator_keyword?
return true if %i[array pair].include?(parent.type)

node.parent.send_type? && !node.parent.parenthesized?
node.parent.send_type?
end

def max_line_length
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/style/if_unless_modifier_spec.rb
Expand Up @@ -457,7 +457,7 @@ def f
end

context 'if-end is argument to a parenthesized method call' do
it "doesn't add redundant parentheses" do
it 'adds parentheses because otherwise it would cause SyntaxError' do
expect_offense(<<~RUBY)
puts("string", if a
^^ Favor modifier `if` usage when having a single-line body. [...]
Expand All @@ -466,7 +466,7 @@ def f
RUBY

expect_correction(<<~RUBY)
puts("string", 1 if a)
puts("string", (1 if a))
RUBY
end
end
Expand Down

0 comments on commit 7ad850b

Please sign in to comment.