Skip to content

Commit 2821564

Browse files
committed
[Fix #12862] Fix a false positive for Style/RedundantLineContinuation
Fixes #12862. This PR fixes a false positive for `Style/RedundantLineContinuation` when line continuations involve `return` with a return value.
1 parent 5f4bbaa commit 2821564

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/style/redundant_line_continuation.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def inside_string_literal?(range, token)
137137
# do_something \
138138
# argument
139139
def method_with_argument?(current_token, next_token)
140-
current_token.type == :tIDENTIFIER && ARGUMENT_TYPES.include?(next_token.type)
140+
return false if current_token.type != :tIDENTIFIER && current_token.type != :kRETURN
141+
142+
ARGUMENT_TYPES.include?(next_token.type)
141143
end
142144

143145
# rubocop:disable Metrics/AbcSize

spec/rubocop/cop/style/redundant_line_continuation_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ def self.foo(bar,#{trailing_whitespace}
114114
RUBY
115115
end
116116

117+
it 'does not register an offense when line continuations involve `return` with a return value' do
118+
expect_no_offenses(<<~'RUBY')
119+
return \
120+
foo
121+
RUBY
122+
end
123+
124+
it 'registers an offense when line continuations involve `return` with a parenthesized return value' do
125+
expect_offense(<<~'RUBY')
126+
return(\
127+
^ Redundant line continuation.
128+
foo
129+
)
130+
RUBY
131+
132+
expect_correction(<<~RUBY)
133+
return(
134+
foo
135+
)
136+
RUBY
137+
end
138+
117139
it 'registers an offense when line continuations with `if`' do
118140
expect_offense(<<~'RUBY')
119141
if foo \

0 commit comments

Comments
 (0)