Skip to content

Commit

Permalink
[Fix rubocop#1988] Do not error in Style/ParallelAssignment when assi…
Browse files Browse the repository at this point in the history
…gning from a constant with colon notation
  • Loading branch information
rrosenblum committed Jun 25, 2015
1 parent 0925327 commit 9873829
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bugs fixed

* [#1988](https://github.com/bbatsov/rubocop/issues/1988): Fix bug in `Style/ParallelAssignment` when assigning from `Module::CONSTANT`. ([@rrosenblum][])

## 0.32.1 (24/06/2015)

### New features
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/parallel_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def on_masgn(node)
# account for edge cases using one variable with a comma
return if left_elements.size == 1

# account for edge case of Constant::CONSTANT
return unless right.array_type?

# allow mass assignment as the return of a method call
return if right.block_type? || right.send_type?

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/parallel_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
it_behaves_like('offenses', ['if true',
' a, b = 1, 2',
'end'].join("\n"))
it_behaves_like('offenses',
'a, b = Float::INFINITY, Float::INFINITY')
it_behaves_like('offenses',
'Float::INFINITY, Float::INFINITY = 1, 2')

shared_examples('allowed') do |source|
it "allows assignment of: #{source}" do
Expand Down Expand Up @@ -77,6 +81,8 @@
'a, b, c = foo'].join("\n"))
it_behaves_like('allowed', ['array = [1, 2, 3]',
'a, = array'].join("\n"))
it_behaves_like('allowed',
'a, b = Float::INFINITY')

it 'hightlights the entire expression' do
inspect_source(cop, 'a, b = 1, 2')
Expand Down

0 comments on commit 9873829

Please sign in to comment.