Skip to content

Commit

Permalink
[Fix #12862] Fix a false positive for Style/RedundantLineContinuation
Browse files Browse the repository at this point in the history
Fixes #12862.

This PR fixes a false positive for `Style/RedundantLineContinuation`
when line continuations involve `return` with a return value.
  • Loading branch information
koic committed Apr 24, 2024
1 parent 5f4bbaa commit 2821564
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12862](https://github.com/rubocop/rubocop/issues/12862): Fix a false positive for `Style/RedundantLineContinuation` when line continuations involve `return` with a return value. ([@koic][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/style/redundant_line_continuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def inside_string_literal?(range, token)
# do_something \
# argument
def method_with_argument?(current_token, next_token)
current_token.type == :tIDENTIFIER && ARGUMENT_TYPES.include?(next_token.type)
return false if current_token.type != :tIDENTIFIER && current_token.type != :kRETURN

ARGUMENT_TYPES.include?(next_token.type)
end

# rubocop:disable Metrics/AbcSize
Expand Down
22 changes: 22 additions & 0 deletions spec/rubocop/cop/style/redundant_line_continuation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ def self.foo(bar,#{trailing_whitespace}
RUBY
end

it 'does not register an offense when line continuations involve `return` with a return value' do
expect_no_offenses(<<~'RUBY')
return \
foo
RUBY
end

it 'registers an offense when line continuations involve `return` with a parenthesized return value' do
expect_offense(<<~'RUBY')
return(\
^ Redundant line continuation.
foo
)
RUBY

expect_correction(<<~RUBY)
return(
foo
)
RUBY
end

it 'registers an offense when line continuations with `if`' do
expect_offense(<<~'RUBY')
if foo \
Expand Down

0 comments on commit 2821564

Please sign in to comment.