Skip to content

Commit

Permalink
[Fix rubocop#12402] Fix false negatives for `Style/RedundantLineConti…
Browse files Browse the repository at this point in the history
…nuation`

Fixes rubocop#12402.

This PR fixes false negatives for `Style/RedundantLineContinuation`
when redundant line continuations for a block are used,
especially without parentheses around first argument.
  • Loading branch information
koic committed Nov 21, 2023
1 parent 10c8d32 commit bce158b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12402](https://github.com/rubocop/rubocop/issues/12402): Fix false negatives for `Style/RedundantLineContinuation` when redundant line continuations for a block are used, especially without parentheses around first argument. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/style/redundant_line_continuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def string_concatenation?(source_line)

def inside_string_literal_or_method_with_argument?(range)
processed_source.tokens.each_cons(2).any? do |token, next_token|
next if token.line == next_token.line

inside_string_literal?(range, token) || method_with_argument?(token, next_token)
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cop/style/redundant_line_continuation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ def self.foo(bar,#{trailing_whitespace}
RUBY
end

it 'registers an offense when redundant line continuations for a block are used, ' \
'especially without parentheses around first argument' do
expect_offense(<<~'RUBY')
let :foo do \
^ Redundant line continuation.
foo(bar, \
^ Redundant line continuation.
baz)
end
RUBY

expect_correction(<<~RUBY)
let :foo do#{' '}
foo(bar,#{' '}
baz)
end
RUBY
end

it 'registers an offense when redundant line continuations for method chain' do
expect_offense(<<~'RUBY')
foo. \
Expand Down

0 comments on commit bce158b

Please sign in to comment.