Skip to content

Commit

Permalink
Merge pull request #1168 from jonas054/1167_fix_multiline_method_calls
Browse files Browse the repository at this point in the history
[Fix #1167] Fix handling of multi-line parameters in TrailingComma
  • Loading branch information
bbatsov committed Jun 23, 2014
2 parents 8724c90 + 5535329 commit f59f14f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
* [#1158](https://github.com/bbatsov/rubocop/issues/1158): Fix auto-correction of floating-point numbers. ([@bbatsov][])
* [#1159](https://github.com/bbatsov/rubocop/issues/1159): Fix checking of `begin`..`end` structures, blocks, and parenthesized expressions in `IndentationWidth`. ([@jonas054][])
* [#1159](https://github.com/bbatsov/rubocop/issues/1159): More rigid conditions for when `attr` is considered an offense. ([@jonas054][])
* [#1167](https://github.com/bbatsov/rubocop/issues/1167): Fix handling of parameters spanning multiple lines in `TrailingComma`. ([@jonas054][])

## 0.23.0 (02/06/2014)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/trailing_comma.rb
Expand Up @@ -114,7 +114,7 @@ def multiline?(node)
end

def on_same_line?(a, b)
[a, b].map(&:line).uniq.size == 1
a.line + a.source.count("\n") == b.line
end

def avoid_comma(kind, comma_begin_pos, sb, extra_info)
Expand Down
24 changes: 16 additions & 8 deletions spec/rubocop/cop/style/trailing_comma_spec.rb
Expand Up @@ -160,13 +160,21 @@
context 'when EnforcedStyleForMultiline is comma' do
let(:cop_config) { { 'EnforcedStyleForMultiline' => 'comma' } }

it 'accepts Array literal with no trailing comma when closing bracket ' \
'is on same line as last value' do
inspect_source(cop, ['VALUES = [',
' 1001,',
' 2020,',
' 3333]'])
expect(cop.offenses).to be_empty
context 'when closing bracket is on same line as last value' do
it 'accepts Array literal with no trailing comma' do
inspect_source(cop, ['VALUES = [',
' 1001,',
' 2020,',
' 3333]'])
expect(cop.offenses).to be_empty
end

it 'accepts a method call with Hash as last parameter split on ' \
'multiple lines' do
inspect_source(cop, ['some_method(a: "b",',
' c: "d")'])
expect(cop.offenses).to be_empty
end
end

it 'accepts Array literal with two of the values on the same line' do
Expand Down Expand Up @@ -262,7 +270,7 @@
" 'auth' => <<-HELP.chomp",
'...',
'HELP',
'},)']) # We still need a comma after the hash.
'})'])
expect(cop.offenses).to be_empty
end
end
Expand Down

0 comments on commit f59f14f

Please sign in to comment.