Skip to content

v1.79.0 introduced unsafe auto correct to Lint/UselessAssignment #14394

@KieranP

Description

@KieranP
def testing
  attempts ||= 1

  do_something
rescue Exception1 => e
  raise e if attempts > 2

  # does something

  attempts += 1
  retry
rescue Exception2 => e
  raise e if attempts > 2

  # does something

  attempts += 1
  retry
end

Expected behavior

Should not change this block of code at all

Actual behavior

The cop makes the first instance of attempts += 1 into attempts + 1, which then splits into attempts\n1, which then gets removed entirely by Lint/Void.

Steps to reproduce the problem

Use above code sample in file.rb, and run rubocop -A file.rb

RuboCop version

› bundle exec rubocop -V
1.79.0 (using Parser 3.3.9.0, Prism 1.4.0, parser_prism, rubocop-ast 1.46.0, analyzing as Ruby 3.4, running on ruby 3.4.4) [arm64-darwin24]
  - rubocop-rails 2.32.0
  - rubocop-performance 1.25.0
  - rubocop-rspec 3.6.0
  - rubocop-rspec_rails 2.31.0
  - rubocop-factory_bot 2.27.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions