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

Fix edge case in omit_parentheses style of Style/MethodCallWithArgsParentheses #7639

Merged
merged 1 commit into from Jan 10, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#7639](https://github.com/rubocop-hq/rubocop/pull/7639): Fix logical operator edge case in `omit_parentheses` style of `Style/MethodCallWithArgsParentheses`. ([@gsamokovarov][])

### Changes

* [#7636](https://github.com/rubocop-hq/rubocop/issues/7636): Remove `console` from `Lint/Debugger` to prevent false positives. ([@gsamokovarov][])
Expand Down
Expand Up @@ -74,10 +74,11 @@ def call_in_literals?(node)
end

def call_in_logical_operators?(node)
node.parent &&
(logical_operator?(node.parent) ||
node.parent.send_type? &&
node.parent.arguments.any?(&method(:logical_operator?)))
parent = node.parent&.block_type? ? node.parent.parent : node.parent
parent &&
(logical_operator?(parent) ||
parent.send_type? &&
parent.arguments.any?(&method(:logical_operator?)))
end

def call_in_optional_arguments?(node)
Expand Down
Expand Up @@ -471,6 +471,11 @@ def seatle_style arg: default(42)
it 'accepts parens in calls with logical operators' do
expect_no_offenses('foo(a) && bar(b)')
expect_no_offenses('foo(a) || bar(b)')
expect_no_offenses(<<~RUBY)
foo(a) || bar(b) do
pass
end
RUBY
end

it 'accepts parens in calls with args with logical operators' do
Expand Down