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 negatives on the Style/RedundantLineContinuation cop #12430

Closed
ydakuka opened this issue Dec 1, 2023 · 13 comments · Fixed by #13609
Closed

False negatives on the Style/RedundantLineContinuation cop #12430

ydakuka opened this issue Dec 1, 2023 · 13 comments · Fixed by #13609
Labels

Comments

@ydakuka
Copy link

ydakuka commented Dec 1, 2023

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
@ydakuka ydakuka changed the title False negative on the Style/RedundantLineContinuation cop False negatives on the Style/RedundantLineContinuation cop Dec 1, 2023
@koic koic added the bug label Dec 2, 2023
@bkuhlmann
Copy link

bkuhlmann commented Mar 2, 2024

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

bkuhlmann referenced this issue in bkuhlmann/hanamismith Mar 2, 2024
Marked this as a follow up action because this is a known bug with link:https://github.com/rubocop/rubocop/issues/12430[RuboCop].

Milestone: patch
bkuhlmann added a commit to bkuhlmann/marameters that referenced this issue Mar 2, 2024
Marked this as a follow up action because this is a known bug with link:rubocop/rubocop#12430.

Milestone: patch
bkuhlmann added a commit to bkuhlmann/versionaire that referenced this issue Mar 2, 2024
Marked this as a follow up action because this is a known bug with link:rubocop/rubocop#12430.

Milestone: patch
@ydakuka
Copy link
Author

ydakuka commented Apr 24, 2024

#12862

@akimd
Copy link

akimd commented Aug 21, 2024

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
Copy link
Contributor

@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
Copy link

akimd commented Aug 21, 2024

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

I opened #13145.

@dvandersluis
Copy link
Member

@ydakuka's false negative examples (#12430 (comment)) and @bkuhlmann's false positive examples (#12430 (comment)) are all fixed now so I'm going to close this issue.

@ydakuka
Copy link
Author

ydakuka commented Dec 14, 2024

@dvandersluis I checked my false negative examples, and except for the first one, they have not been fixed yet.

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.69.2 (using Parser 3.3.4.2, rubocop-ast 1.36.2, analyzing as Ruby 2.7, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.23.0
  - rubocop-rails 2.27.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 3.3.0
  - rubocop-rspec_rails 2.30.0
  - rubocop-thread_safety 0.6.0

@dvandersluis
Copy link
Member

dvandersluis commented Dec 19, 2024

@ydakuka what version of rubocop are you using? I tried this on master, and all 5 continuations are flagged:

# test.rb
# frozen_string_literal: true

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 test.rb --only Style/RedundantLineContinuation
Inspecting 1 file
C

Offenses:

test.rb:10:35: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    redirect_to user_path(@user), \ ...
                                  ^
test.rb:20:21: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    my_bar: my_bar, \ ...
                    ^
test.rb:25:17: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
  create(:user, \ ...
                ^
test.rb:26:21: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    my_foo: my_foo, \ ...
                    ^
test.rb:28:21: C: [Correctable] Style/RedundantLineContinuation: Redundant line continuation.
    my_baz: my_baz, \ ...
                    ^

1 file inspected, 5 offenses detected, 5 offenses autocorrectable

@ydakuka
Copy link
Author

ydakuka commented Dec 19, 2024

@dvandersluis

I am currently using rubocop version 1.69.2

I can provide snippets to help reproduce the issue:

RSpec.describe User do
  describe 'associations' do
    specify do
      expect(user).to \
        belong_to(:profile)
    end
  end

  describe '.custom_search' do
    let! :user do
      create(:user,
             my_foo: my_foo,
             my_bar: my_bar, \
             my_barbaz: my_barbaz)
    end

    pending 'add tests'
  end
end
RSpec.describe OrderDecorator do
  describe '#remained' do
    let! :balance do
      create(:balance, \
             _id: order.id, value: value)
    end

    pending 'add tests'
  end

  describe '#document_link_tag' do
    it 'returns link with proper content' do
      expect(elem.inner_html).to eq \
        Order.human_attribute_name(:document_link)
    end
  end
end

@dvandersluis
Copy link
Member

@ydakuka thank you for the examples. I have replicated the false negatives now, and opened #13609 to fix them.

@dvandersluis dvandersluis reopened this Dec 19, 2024
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Dec 19, 2024
…uation` when continuations are inside begin nodes
@koic koic closed this as completed in b7c5c6e Dec 23, 2024
koic added a commit that referenced this issue Dec 23, 2024
[Fix #12430] Fix false negatives in `Style/RedundantLineContinuation` when continuations are inside begin nodes
@ydakuka
Copy link
Author

ydakuka commented Jan 11, 2025

I updated rubocop to version 1.70.0 in my project, fixed all offenses, and found more false negatives.

RSpec.describe Campaigns::CloneInteractor do
  let :campaign_location do
    create(:campaign_location, \
           %i[allowed disallowed].sample,
           created_at: campaign_location_created_at)
  end

  pending 'add something'
end
RSpec.describe 'POST /api/v1/rewards' do
  def make_request
    post send(:"user_#{provider_name}_omniauth_callback_path"), \
         params: {},
         headers: { 'ACCEPT' => 'text/html' }
  end

  pending 'add something'
end

@Earlopain
Copy link
Contributor

Can you make a new issue please?

@ydakuka
Copy link
Author

ydakuka commented Jan 11, 2025

Sure, #13677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants