From 85ba07b4ec3714aa88a73d2eceb74ae0e4bb38f2 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Sun, 27 Jan 2019 20:46:57 +0100 Subject: [PATCH] Fix a bug in Layout/ClosingParenthesisIndentation 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 16531120c0a05d824c2ff1bc6ccb2bf070. --- .../cop/layout/closing_parenthesis_indentation.rb | 9 +++++---- .../layout/closing_parenthesis_indentation_spec.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb b/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb index 7480a2ed6c5..0c5840b8a79 100644 --- a/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +++ b/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb @@ -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 diff --git a/spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb b/spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb index 58c48e985e4..2d38abb86e3 100644 --- a/spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb +++ b/spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb @@ -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,