rubocop / rubocop

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

Style/RedundantLineContinuation: false positive #13145

Open akimd opened 3 weeks ago

akimd commented 3 weeks ago

Hi,

In the following example the backslash is absolutely needed, yet the cop wants to get rid of it.

$ 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

Cheers!


Expected behavior

No complaint.

Actual behavior

Complaint.

RuboCop version

$ bundle exec rubocop -V
1.65.1 (using Parser 3.3.4.2, rubocop-ast 1.32.1, running on ruby 3.3.4) [arm64-darwin23]
  - rubocop-performance 1.21.1
koic commented 3 weeks ago

This is a false positive, not a false negative.

akimd commented 3 weeks ago

Of course, sorry.

akimd commented 3 days ago

Another example of false positive. I don't know if it's the same bug.

# frozen_string_literal: true

def fun
  foo
    .bar(12) \
  || baz
end
$ bundle exec rubocop contline.rb
Inspecting 1 file
C

Offenses:

contline.rb:5:14: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    .bar(12) \ ...
             ^

1 file inspected, 1 offense detected, 1 offense autocorrectable
$ bundle exec rubocop -V
1.66.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.4) [arm64-darwin23]
  - rubocop-performance 1.21.1