diff --git a/changelog/fix_a_false_positive_for_layout_redundant_line_break.md b/changelog/fix_a_false_positive_for_layout_redundant_line_break.md new file mode 100644 index 000000000000..a27f3f96061a --- /dev/null +++ b/changelog/fix_a_false_positive_for_layout_redundant_line_break.md @@ -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][]) diff --git a/lib/rubocop/cop/layout/redundant_line_break.rb b/lib/rubocop/cop/layout/redundant_line_break.rb index 094a51000162..6d029e92f8ed 100644 --- a/lib/rubocop/cop/layout/redundant_line_break.rb +++ b/lib/rubocop/cop/layout/redundant_line_break.rb @@ -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 diff --git a/spec/rubocop/cop/layout/redundant_line_break_spec.rb b/spec/rubocop/cop/layout/redundant_line_break_spec.rb index 67de214ee561..6f6d1b20eafc 100644 --- a/spec/rubocop/cop/layout/redundant_line_break_spec.rb +++ b/spec/rubocop/cop/layout/redundant_line_break_spec.rb @@ -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