Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an infinite loop error for Layout/ArrayAlignment #11537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11537](https://github.com/rubocop/rubocop/pull/11537): Fix an infinite loop error for `Layout/ArrayAlignment` when using assigning unbracketed array elements. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/array_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def base_column(node, args)
end

def target_method_lineno(node)
node.loc.line
node.bracketed? ? node.loc.line : node.parent.loc.line
end
end
end
Expand Down
33 changes: 33 additions & 0 deletions spec/rubocop/cop/layout/array_alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@
RUBY
end

it 'accepts when assigning aligned bracketed array elements' do
expect_no_offenses(<<~RUBY)
var = [
first,
second
]
RUBY
end

it 'accepts when assigning aligned unbracketed array elements' do
expect_no_offenses(<<~RUBY)
var =
first,
second
RUBY
end

it 'registers an offense when assigning not aligned unbracketed array elements' do
expect_offense(<<~RUBY)
var =
first,
^^^^^ Use one level of indentation for elements following the first line of a multi-line array.
second
^^^^^^ Use one level of indentation for elements following the first line of a multi-line array.
RUBY

expect_correction(<<~RUBY)
var =
first,
second
RUBY
end

it 'accepts single line array' do
expect_no_offenses('array = [ a, b ]')
end
Expand Down