Skip to content

Commit

Permalink
Merge pull request #9911 from jonas054/9905_LineEndStringConcatenatio…
Browse files Browse the repository at this point in the history
…nIndentation_bug

[Fix #9905] Fix single line concatenation false positive
  • Loading branch information
koic committed Jul 4, 2021
2 parents ae0deb3 + 98a5a12 commit e5db7c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/fix_line_end_string_concatenation_indentation.md
@@ -0,0 +1 @@
* [#9905](https://github.com/rubocop/rubocop/issues/9905): Fix false positive for single line concatenation in `Layout/LineEndStringConcatenationIndentation`. ([@jonas054][])
Expand Up @@ -85,14 +85,9 @@ def autocorrect(corrector, node)
private

def strings_concatenated_with_backslash?(dstr_node)
!dstr_node.heredoc? &&
!single_string_literal?(dstr_node) &&
dstr_node.children.length > 1 &&
dstr_node.children.all? { |c| c.str_type? || c.dstr_type? }
end

def single_string_literal?(dstr_node)
dstr_node.loc.respond_to?(:begin) && dstr_node.loc.begin
dstr_node.multiline? &&
dstr_node.children.all? { |c| c.str_type? || c.dstr_type? } &&
dstr_node.children.none?(&:multiline?)
end

def always_indented?(dstr_node)
Expand Down
Expand Up @@ -14,6 +14,21 @@
let(:cop_indent) { nil } # use indentation width from Layout/IndentationWidth

shared_examples 'common' do
it 'accepts single line string literal concatenation' do
expect_no_offenses(<<~'RUBY')
text = 'offense'
puts 'This probably should not be '"an #{text}"
RUBY
end

it 'accepts string literal with line break concatenated with other string' do
expect_no_offenses(<<~'RUBY')
text = 'offense'
puts 'This probably
should not be '"an #{text}"
RUBY
end

it 'accepts a multiline string literal' do
expect_no_offenses(<<~'RUBY')
puts %(
Expand Down

0 comments on commit e5db7c0

Please sign in to comment.