Skip to content

Commit

Permalink
Fix a bug in Layout/ClosingParenthesisIndentation
Browse files Browse the repository at this point in the history
ClosingParenthesisIndentation would complain about

    block_adds_extra_indentation do
      some_method(a,
        x: 1,
        y: 2
      )
    end

saying it should be indented as:

    block_adds_extra_indentation do
      some_method(a,
        x: 1,
        y: 2
    )
    end

This issue appeared after the bugfix commit 1653112.
  • Loading branch information
bquorning committed Jan 28, 2019
1 parent 80f2fb6 commit 85ba07b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 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
14 changes: 14 additions & 0 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

0 comments on commit 85ba07b

Please sign in to comment.