Skip to content

Commit

Permalink
Merge pull request #2873 from jonas054/2845_multiline_method_call_paren
Browse files Browse the repository at this point in the history
[Fix #2845] Handle heredocs in MultilineLiteralBraceLayout auto-correct
  • Loading branch information
bbatsov committed Feb 23, 2016
2 parents 5ce3274 + aa9f2cd commit da1f7ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* [#2861](https://github.com/bbatsov/rubocop/pull/2861): Fix false positive in `Style/SpaceAroundKeyword` for `rescue(...`. ([@rrosenblum][])
* [#2832](https://github.com/bbatsov/rubocop/issues/2832): `Style/MultilineOperationIndentation` treats operations inside blocks inside other operations correctly. ([@jonas054][])
* [#2865](https://github.com/bbatsov/rubocop/issues/2865): Change `require:` in config to be relative to the `.rubocop.yml` file itself. ([@ptarjan][])
* [#2845](https://github.com/bbatsov/rubocop/issues/2845): Handle heredocs in `Style/MultilineLiteralBraceLayout` auto-correct. ([@jonas054][])
* [#2848](https://github.com/bbatsov/rubocop/issues/2848): Handle comments inside arrays in `Style/MultilineArrayBraceLayout` auto-correct. ([@jonas054][])

## 0.37.2 (11/02/2016)

Expand Down
12 changes: 6 additions & 6 deletions lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def autocorrect(node)
corrector.insert_before(node.loc.end, "\n".freeze)
end
else
range = Parser::Source::Range.new(
node.source_range.source_buffer,
children(node).last.source_range.end_pos,
node.loc.end.begin_pos)

->(corrector) { corrector.remove(range) }
lambda do |corrector|
corrector.remove(range_with_surrounding_space(node.loc.end,
:left))
corrector.insert_after(children(node).last.source_range,
node.loc.end.source)
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/style/multiline_array_brace_layout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
end

it 'autocorrects closing brace on different line from last element' do
new_source = autocorrect_source(cop, ['[a,',
'b',
new_source = autocorrect_source(cop, ['[a, # a',
'b # b',
']'])

expect(new_source).to eq("[a,\nb]")
expect(new_source).to eq("[a, # a\nb] # b")
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/style/multiline_method_call_brace_layout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,15 @@

expect(new_source).to eq("foo(\n1,\n2\n)")
end

it 'autocorrects method call with heredoc' do
new_source = autocorrect_source(cop, ['def foo',
' bar(<<EOM',
' baz',
'EOM',
' )',
'end'])
expect(new_source).to eq("def foo\n bar(<<EOM)\n baz\nEOM\nend")
end
end
end

0 comments on commit da1f7ab

Please sign in to comment.