Skip to content

Commit

Permalink
[Fix #7719] Fix Style/NestedParenthesizedCalls cop for newline
Browse files Browse the repository at this point in the history
Closes #7719
  • Loading branch information
tejasbubane authored and bbatsov committed Feb 19, 2020
1 parent d4d479c commit 0c3afb7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#7719](https://github.com/rubocop-hq/rubocop/issues/7719): Fix `Style/NestedParenthesizedCalls` cop for newline. ([@tejasbubane][])

## 0.80.0 (2020-02-18)

### New features
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/nested_parenthesized_calls.rb
Expand Up @@ -35,8 +35,8 @@ def autocorrect(nested)
last_arg = nested.last_argument.source_range

leading_space =
range_with_surrounding_space(range: first_arg,
side: :left).begin.resize(1)
range_with_surrounding_space(range: first_arg.begin,
side: :left)

lambda do |corrector|
corrector.replace(leading_space, '(')
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb
Expand Up @@ -100,4 +100,18 @@
expect_no_offenses('expect(object1.attr = 1).to eq 1')
end
end

context 'backslash newline in method call' do
let(:source) do
<<~RUBY
puts(nex \
5)
RUBY
end

it 'auto-corrects by adding parentheses' do
new_source = autocorrect_source(source.strip)
expect(new_source).to eq('puts(nex(5))')
end
end
end

0 comments on commit 0c3afb7

Please sign in to comment.