Skip to content

Commit

Permalink
Merge pull request #12867 from koic/fix_false_positive_for_style_redu…
Browse files Browse the repository at this point in the history
…ndant_line_continuation

[Fix #12862] Fix a false positive for `Style/RedundantLineContinuation`
  • Loading branch information
koic committed Apr 25, 2024
2 parents 84877a3 + 2821564 commit a8ef19c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
@@ -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
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
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 a8ef19c

Please sign in to comment.