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

False positive with Style/RedundantLineContinuation #11844

Closed
koppen opened this issue May 4, 2023 · 3 comments · Fixed by #11845
Closed

False positive with Style/RedundantLineContinuation #11844

koppen opened this issue May 4, 2023 · 3 comments · Fixed by #11845
Labels

Comments

@koppen
Copy link

koppen commented May 4, 2023

Expected behavior

Running rubocop --only Style/RedundantLineContinuation on the following code:

# lib/tasks/sample.rake
namespace :sample do
  desc \
    "Here comes a long multiline description"
  task :stuff
end

should result in no offenses detected:

1 file inspected, no offenses detected

and running rubocop --only Style/RedundantLineContinuation --autocorrect should not touch the file.

Actual behavior

Running rubocop --only Style/RedundantLineContinuation flags the line continuation as being redundant (which it isn't):

Offenses:

lib/tasks/sample.rake:5:10: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    desc \ ...
         ^

1 file inspected, 1 offense detected, 1 offense autocorrectable

and running safe autocorrections on it changes it to invalid syntax:

namespace :sample do
  desc
  "Here comes a long multiline description"
  task :stuff
end

which results in

$ rake -T
rake aborted!
ArgumentError: wrong number of arguments (given 0, expected 1)

RuboCop version

$ bundle exec rubocop -V
1.50.2 (using Parser 3.2.2.1, rubocop-ast 1.28.1, running on ruby 3.1.2) [arm64-darwin21]
  - rubocop-capybara 2.18.0
  - rubocop-rails 2.19.1
  - rubocop-rspec 2.20.0

While this looks a lot like a duplicate of #11783, the fix for that issue is already in 1.50.2 as far as I can tell.

@koic
Copy link
Member

koic commented May 4, 2023

Hhm, I cannot reproduce this issue with the latest master branch and v1.50.2:

$ cat example.rb
desc \
  "Here comes a long multiline description"

$ bundle exec rubocop --only Style/RedundantLineContinuation example.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

@koppen
Copy link
Author

koppen commented May 4, 2023

Hm, hang on, let me see what I am missing in the repro code

@koppen
Copy link
Author

koppen commented May 4, 2023

Ah, it needs to be wrapped in a block as well - in this case a namespace. I've updated the issue to reflect this.

@koic koic added the bug label May 4, 2023
bbatsov pushed a commit that referenced this issue May 4, 2023
Fixes #11844.

This PR fixes a false positive for `Style/RedundantLineContinuation` when
using line concatenation for assigning a return value and without argument parentheses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants