Skip to content

Commit

Permalink
Merge pull request #6351 from antonzaytsev/fix/layout-closing-parenth…
Browse files Browse the repository at this point in the history
…esis-indentation-multiline-param

Fix a false positive for `Layout/ClosingParenthesisIndentation`
  • Loading branch information
Drenmi committed Jan 22, 2019
2 parents 08ca192 + 603397a commit 95e58a2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@

* [#6254](https://github.com/rubocop-hq/rubocop/issues/6254): Fix `Layout/RescueEnsureAlignment` for non-local assignments. ([@marcotc][])
* [#6648](https://github.com/rubocop-hq/rubocop/issues/6648): Fix auto-correction of `Style/EmptyLiteral` when `Hash.new` is passed as the first argument to `super`. ([@rrosenblum][])
* [#6351](https://github.com/rubocop-hq/rubocop/pull/6351): Fix a false positive for `Layout/ClosingParenthesisIndentation` when first argument is multiline. ([@antonzaytsev][])

## 0.63.1 (2019-01-22)

Expand Down Expand Up @@ -3773,6 +3774,7 @@
[@tom-lord]: https://github.com/tom-lord
[@bayandin]: https://github.com/bayandin
[@nadiyaka]: https://github.com/nadiyaka
[@antonzaytsev]: https://github.com/antonzaytsev
[@amatsuda]: https://github.com/amatsuda
[@Intrepidd]: https://github.com/Intrepidd
[@Ruffeng]: https://github.com/Ruffeng
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/layout/closing_parenthesis_indentation.rb
Expand Up @@ -147,7 +147,7 @@ def expected_column(left_paren, elements)
left_paren.column
else
source_indent = processed_source
.line_indentation(last_argument_line(elements))
.line_indentation(first_argument_line(elements))
new_indent = source_indent - indentation_width

new_indent < 0 ? 0 : new_indent
Expand All @@ -161,9 +161,9 @@ def all_elements_aligned?(elements)
.count == 1
end

def last_argument_line(elements)
def first_argument_line(elements)
elements
.last
.first
.loc
.first_line
end
Expand Down
21 changes: 21 additions & 0 deletions spec/rubocop/cop/layout/closing_parenthesis_indentation_spec.rb
Expand Up @@ -500,6 +500,27 @@ 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 95e58a2

Please sign in to comment.