A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/issues/14383 below:

`Lint/UselessAssignment` false positive for loop with conditional · Issue #14383 · rubocop/rubocop · GitHub

def f
  string = "a"
  last_c = false
  while string.size < 11
    if string[-1] == 'c'
      string += "b"
      last_c = false
    else
      string += "c"
      last_c = true
    end
  end

  last_c
end
Expected behavior

No Lint/UselessAssignment offenses

Actual behavior
test.rb:5:7: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - string. (https://rubystyle.guide#underscore-unused-vars)
      string += "b"
Steps to reproduce the problem

Run provided code on latest RuboCop version.

Likely caused by #14377

RuboCop version
1.79.0 (using Parser 3.3.8.0, Prism 1.4.0, parser_prism, rubocop-ast 1.46.0, analyzing as Ruby 3.4, running on ruby 3.4.4) [x86_64-linux]

mscrivo, ntkme, franzliedke and jacksonhuether


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4