KEMBAR78
false positive for Lint/UselessAssignment with until loop · Issue #14402 · rubocop/rubocop · GitHub
Skip to content

false positive for Lint/UselessAssignment with until loop #14402

@seandilda

Description

@seandilda

I have some text parsing code that passed all lints with rubocop 1.77.0 but has a Lint/UselessAssignment offense as of 1.79.0

I managed to simplify the code to this example:

# frozen_string_literal: true

list = '3234(234)23'.chars
in_parens = false
until list.empty?
  c = list.shift
  if in_parens
    if c == ')'
      in_parens = false
    else
      $stdout.puts c
    end
  elsif c == '('
    in_parens = true
  end
end

Expected behavior

No offenses

Actual behavior

$ rubocop --debug test.rb
For /app: configuration from /app/.rubocop.yml
Default configuration from /home/docker-user/bundle/ruby/3.3.0/gems/rubocop-1.79.0/config/default.yml
Plugin configuration from /home/docker-user/bundle/ruby/3.3.0/gems/rubocop-rails-2.32.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /app/test.rb
W

Offenses:

test.rb:9:7: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - in_parens.
      in_parens = false
      ^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable
Finished in 0.26479940899298526 seconds

Steps to reproduce the problem

See sample code above

RuboCop version

1.79.0 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.3.7) [x86_64-linux]
  - rubocop-rails 2.32.0

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