Skip to content

Commit

Permalink
[Fix rubocop#10403] Fix an error for Style/StringConcatenation
Browse files Browse the repository at this point in the history
Fixes rubocop#10403.

This PR fixes an error for `Style/StringConcatenation`
when string concatenation with multiline heredoc text.
  • Loading branch information
koic committed Feb 8, 2022
1 parent af609e5 commit 11dde02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_string_concatenation.md
@@ -0,0 +1 @@
* [#10403](https://github.com/rubocop/rubocop/issues/10403): Fix an error for `Style/StringConcatenation` when string concatenation with multiline heredoc text. ([@koic][])
8 changes: 7 additions & 1 deletion lib/rubocop/cop/style/string_concatenation.rb
Expand Up @@ -134,7 +134,13 @@ def plus_node?(node)
end

def uncorrectable?(part)
part.multiline? || (part.str_type? && part.heredoc?) || part.each_descendant(:block).any?
part.multiline? || heredoc?(part) || part.each_descendant(:block).any?
end

def heredoc?(node)
return false unless node.str_type? || node.dstr_type?

node.heredoc?
end

def corrected_ancestor?(node)
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/style/string_concatenation_spec.rb
Expand Up @@ -143,6 +143,18 @@

expect_no_corrections
end

it 'registers an offense but does not correct when string concatenation with multiline heredoc text' do
expect_offense(<<~RUBY)
"foo" + <<~TEXT
^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation.
bar
baz
TEXT
RUBY

expect_no_corrections
end
end

context 'double quotes inside string' do
Expand Down

0 comments on commit 11dde02

Please sign in to comment.