From 0c3afb780d02b9f9e131761d3311020200d1ab31 Mon Sep 17 00:00:00 2001 From: Tejas Bubane Date: Wed, 19 Feb 2020 12:15:32 +0530 Subject: [PATCH] [Fix #7719] Fix `Style/NestedParenthesizedCalls` cop for newline Closes https://github.com/rubocop-hq/rubocop/issues/7719 --- CHANGELOG.md | 4 ++++ .../cop/style/nested_parenthesized_calls.rb | 4 ++-- .../cop/style/nested_parenthesized_calls_spec.rb | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7343e4ddbe4..5d1a5111ea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/style/nested_parenthesized_calls.rb b/lib/rubocop/cop/style/nested_parenthesized_calls.rb index e4392f59f03..f7a624242d4 100644 --- a/lib/rubocop/cop/style/nested_parenthesized_calls.rb +++ b/lib/rubocop/cop/style/nested_parenthesized_calls.rb @@ -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, '(') diff --git a/spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb b/spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb index aeb62378a7d..8da392561ca 100644 --- a/spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb +++ b/spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb @@ -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