Skip to content

Commit

Permalink
Mark HeredocArgumentClosingParenthesis as incompatible with TrailingC…
Browse files Browse the repository at this point in the history
…ommaInArguments
  • Loading branch information
Buildkite authored and bbatsov committed May 28, 2019
1 parent 958cf68 commit f003267
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Bug fixes

* [#6936](https://github.com/rubocop-hq/rubocop/issues/6936): Fix `Layout/MultilineMethodArgumentLineBreaks` when bracket hash assignment on multiple lines. ([@maxh][])
* Mark `Layout/HeredocArgumentClosingParenthesis` incompatible with `Style/TrailingCommaInArguments`. ([@maxh][])

## 0.70.0 (2019-05-21)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def autocorrect(node)
end
end

def self.autocorrect_incompatible_with
[Style::TrailingCommaInArguments]
end

private

def outermost_send_on_same_line(heredoc)
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/style/trailing_comma_in_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def autocorrect(range)
PunctuationCorrector.swap_comma(range)
end

def self.autocorrect_incompatible_with
[Layout::HeredocArgumentClosingParenthesis]
end

private

def avoid_autocorrect?(args)
Expand Down
31 changes: 31 additions & 0 deletions spec/rubocop/cli/cli_autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1563,4 +1563,35 @@ def method_a
end
RUBY
end

it 'corrects HeredocArgumentClosingParenthesis offenses and ' \
'ignores TrailingCommaInArguments offense' do
create_file('example.rb', <<~RUBY)
result = foo(
# comment
<<~SQL.squish
SELECT * FROM bar
SQL
)
RUBY
create_file('.rubocop.yml', <<~YAML)
Layout/HeredocArgumentClosingParenthesis:
Enabled: true
Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: comma
YAML

expect(cli.run(%w[--auto-correct])).to eq(1)
expect($stderr.string).to eq('')
expect(IO.read('example.rb')).to eq(<<~RUBY)
# frozen_string_literal: true
result = foo(
# comment
<<~SQL.squish)
SELECT * FROM bar
SQL
RUBY
end
end

0 comments on commit f003267

Please sign in to comment.