Skip to content

Commit

Permalink
Merge pull request #6712 from bquorning/closing-parenthesis-indentati…
Browse files Browse the repository at this point in the history
…on-bugfix

Fix a bug in Layout/ClosingParenthesisIndentation
  • Loading branch information
bquorning committed Jan 28, 2019
2 parents a41aeb6 + 85ba07b commit b6cf0dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
9 changes: 5 additions & 4 deletions lib/rubocop/cop/layout/closing_parenthesis_indentation.rb
Expand Up @@ -142,15 +142,16 @@ def check_for_no_elements(node)
end

def expected_column(left_paren, elements)
if !line_break_after_left_paren?(left_paren, elements) &&
all_elements_aligned?(elements)
left_paren.column
else
if line_break_after_left_paren?(left_paren, elements)
source_indent = processed_source
.line_indentation(first_argument_line(elements))
new_indent = source_indent - indentation_width

new_indent < 0 ? 0 : new_indent
elsif all_elements_aligned?(elements)
left_paren.column
else
processed_source.line_indentation(first_argument_line(elements))
end
end

Expand Down
56 changes: 35 additions & 21 deletions spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb
Expand Up @@ -75,6 +75,20 @@
RUBY
end

it 'accepts a correctly indented ) inside a block' do
expect_no_offenses(<<-RUBY.strip_indent)
block_adds_extra_indentation do
some_method(a,
x: 1,
y: 2
)
b =
some_method(a,
)
end
RUBY
end

it 'autocorrects misindented )' do
corrected = autocorrect_source(<<-RUBY.strip_indent)
some_method(a,
Expand Down Expand Up @@ -116,6 +130,27 @@
RUBY
end
end

context 'with first multiline arg on new line' do
it 'accepts ) on the same level as ( with args on same line' do
expect_no_offenses(<<-RUBY.strip_indent)
where(
"multiline
condition", second_arg
)
RUBY
end

it 'accepts ) on the same level as ( with second arg on new line' do
expect_no_offenses(<<-RUBY.strip_indent)
where(
"multiline
condition",
second_arg
)
RUBY
end
end
end

context 'for method assignments with indented parameters' do
Expand Down Expand Up @@ -500,27 +535,6 @@ def some_method()
end
end

context 'method call with first multiline arg on new line' do
it 'accepts ) on the same level as ( with args on same line' do
expect_no_offenses(<<-RUBY.strip_indent)
where(
"multiline
condition", second_arg
)
RUBY
end

it 'accepts ) on the same level as ( with second arg on new line' do
expect_no_offenses(<<-RUBY.strip_indent)
where(
"multiline
condition",
second_arg
)
RUBY
end
end

it 'accepts begin nodes that are not grouped expressions' do
expect_no_offenses(<<-RUBY.strip_indent)
def a
Expand Down

0 comments on commit b6cf0dd

Please sign in to comment.