rubocop / rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.
https://docs.rubocop.org
MIT License
12.6k stars 3.05k forks source link

False negatives on the `Style/RedundantLineContinuation` cop #12430

Open ydakuka opened 9 months ago

ydakuka commented 9 months ago

Describe the solution you'd like

def create
  # TODO: some code

  if @user.confirmed?
    redirect_to user_path(@user),
                notice: translate('confirmed') and return
  elsif @user.condition?
    redirect_to user_path(@user), \
                notice: translate('not_confirmed') and return
  end

  # TODO: some code
end
let! :user do
  create(:user,
         my_foo: my_foo,
         my_bar: my_bar, \
         my_barbaz: my_barbaz)
end
let! :user do
  create(:user, \
         my_foo: my_foo, \
         my_bar: my_bar,
         my_baz: my_baz, \
         my_foobar: my_foobar)
end

Rubocop

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.58.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.19.0
  - rubocop-factory_bot 2.24.0
  - rubocop-performance 1.19.1
  - rubocop-rails 2.22.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.25.0
  - rubocop-thread_safety 0.5.1
bkuhlmann commented 6 months ago

To add to the above, I'm seeing this issue crop up in the RuboCop 1.61.0 release for the first time as well. Here's a few more examples:

# Example: String Concatenation
expect(temp_dir.join("test/Procfile.dev").read).to eq(
  %(web: rerun --dir app,config,lib,slices --pattern="**/*.{erb,rb}" ) \  # <-- Flagged, incorrectly, as redundant line continuation
  "-- bundle exec puma --config ./config/puma.rb\n" \
  "assets: bundle exec hanami assets watch\n"
)

# Example: Pattern Matching
parameters in [[:rest]] \  # <-- Flagged, incorrectly, as redundant line continuation
              | [[:keyrest]] \. # <-- Flagged, incorrectly, as redundant line continuation
              | [[:rest], [:keyrest]] \  # <-- Flagged, incorrectly, as redundant line continuation
              | [[:rest, :*]] \  # <-- Flagged, incorrectly, as redundant line continuation
              | [[:keyrest, :**]] \  # <-- Flagged, incorrectly, as redundant line continuation
              | [[:rest, :*], [:keyrest, :**]]
RuboCop Version Details ``` 1.61.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.3.0) [arm64-darwin23.3.0] - rubocop-capybara 2.20.0 - rubocop-factory_bot 2.25.1 - rubocop-packaging 0.5.2 - rubocop-performance 1.20.2 - rubocop-rake 0.6.0 - rubocop-rspec 2.27.0 - rubocop-thread_safety 0.5.1 ```
ydakuka commented 4 months ago

https://github.com/rubocop/rubocop/issues/12862

akimd commented 3 weeks ago

I'm facing the same issue.

$ cat backslash.rb
puts foo(123,
         123) \
     == bar
$ bundle exec rubocop backslash.rb
Inspecting 1 file
C

Offenses:

backslash.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
puts foo(123,
^
backslash.rb:2:15: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
         123) \ ...
              ^

1 file inspected, 2 offenses detected, 2 offenses autocorrectable
Earlopain commented 3 weeks ago

@akimd can you make a new issue? This is about code that should register an offense. I think your problem is about the opposite?

akimd commented 3 weeks ago

Bummer, I read "false positive", but it's about false negatives, you are right. Sorry.

I opened https://github.com/rubocop/rubocop/issues/13145.