Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #9905] Fix single line concatenation false positive #9911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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