From 09ee45ed0f24db53abbb81f19b1e1b088f9ec562 Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Wed, 23 Sep 2020 16:07:39 -0400 Subject: [PATCH] [Fix #8774] Fix false positive with `Layout/ArrayAlignment` for parallel assignment. --- CHANGELOG.md | 4 ++++ lib/rubocop/cop/layout/array_alignment.rb | 1 + spec/rubocop/cop/layout/array_alignment_spec.rb | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44a9d4dcb73..357dcc8674f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [#8774](https://github.com/rubocop-hq/rubocop/issues/8774): Fix a false positive for `Layout/ArrayAlignment` with parallel assignment. ([@dvandersluis][]) + ## 0.91.1 (2020-09-23) ### Bug fixes diff --git a/lib/rubocop/cop/layout/array_alignment.rb b/lib/rubocop/cop/layout/array_alignment.rb index ea57a425ed6..4c76d3368df 100644 --- a/lib/rubocop/cop/layout/array_alignment.rb +++ b/lib/rubocop/cop/layout/array_alignment.rb @@ -44,6 +44,7 @@ class ArrayAlignment < Cop def on_array(node) return if node.children.size < 2 + return if node.parent&.masgn_type? check_alignment(node.children, base_column(node, node.children)) end diff --git a/spec/rubocop/cop/layout/array_alignment_spec.rb b/spec/rubocop/cop/layout/array_alignment_spec.rb index e44d68f89a6..2504bba10e8 100644 --- a/spec/rubocop/cop/layout/array_alignment_spec.rb +++ b/spec/rubocop/cop/layout/array_alignment_spec.rb @@ -169,6 +169,13 @@ ] RUBY end + + it 'does not register an offense or try to correct parallel assignment' do + expect_no_offenses(<<~RUBY) + thing, foo = + 1, 2 + RUBY + end end context 'when aligned with fixed indentation' do @@ -328,5 +335,12 @@ ] RUBY end + + it 'does not register an offense or try to correct parallel assignment' do + expect_no_offenses(<<~RUBY) + thing, foo = + 1, 2 + RUBY + end end end