Skip to content

Commit

Permalink
[Fix rubocop#11949] Fix a false positive for Layout/RedundantLineBreak
Browse files Browse the repository at this point in the history
Fixes rubocop#11949.

This PR fixes a false positive for `Layout/RedundantLineBreak`
when using a line broken string.
  • Loading branch information
koic committed Jun 14, 2023
1 parent c9bc24c commit 820ec28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11949](https://github.com/rubocop/rubocop/issues/11949): Fix a false positive for `Layout/RedundantLineBreak` when using a line broken string. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/redundant_line_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def single_line_block_chain_enabled?
def suitable_as_single_line?(node)
!comment_within?(node) &&
node.each_descendant(:if, :case, :kwbegin, :def).none? &&
node.each_descendant(:dstr, :str).none?(&:heredoc?) &&
node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
node.each_descendant(:begin).none? { |b| !b.single_line? }
end

Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/layout/redundant_line_break_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ def resolve_inheritance_from_gems(hash)
.baz
RUBY
end

it 'does not register an offense with a line broken string argument' do
expect_no_offenses(<<~RUBY)
foo('
xyz
')
.bar
.baz
RUBY
end
end
end

Expand Down

0 comments on commit 820ec28

Please sign in to comment.