Skip to content

Commit

Permalink
Merge pull request rubocop#11950 from koic/fix_a_false_positive_for_l…
Browse files Browse the repository at this point in the history
…ayout_redundant_line_break

[Fix rubocop#11949] Fix a false positive for `Layout/RedundantLineBreak`
  • Loading branch information
koic authored Jun 14, 2023
2 parents ae82e46 + 820ec28 commit 144b578
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 144b578

Please sign in to comment.