Title: Lint/UselessAssignment: false positives with `+=` · Issue #14419 · rubocop/rubocop · GitHub
Open Graph Title: Lint/UselessAssignment: false positives with `+=` · Issue #14419 · rubocop/rubocop
X Title: Lint/UselessAssignment: false positives with `+=` · Issue #14419 · rubocop/rubocop
Description: Lint/UselessAssignment reports false positives even after 1.79.1 and #14409 Expected behavior rubocop should not report a violation Actual behavior Rubocop reports lines 8 and 12 are useless assignments, but not 16 for some reason. If I ...
Open Graph Description: Lint/UselessAssignment reports false positives even after 1.79.1 and #14409 Expected behavior rubocop should not report a violation Actual behavior Rubocop reports lines 8 and 12 are useless assign...
X Description: Lint/UselessAssignment reports false positives even after 1.79.1 and #14409 Expected behavior rubocop should not report a violation Actual behavior Rubocop reports lines 8 and 12 are useless assign...
Opengraph URL: https://github.com/rubocop/rubocop/issues/14419
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lint/UselessAssignment: false positives with `+=`","articleBody":"`Lint/UselessAssignment` reports false positives even after `1.79.1` and https://github.com/rubocop/rubocop/pull/14409\n\n## Expected behavior\n\nrubocop should not report a violation\n\n## Actual behavior\n\nRubocop reports lines 8 and 12 are useless assignments, but not 16 for some reason. If I remove line 4, then the false positives are eliminated.\n\n## Steps to reproduce the problem\n\n```ruby\ndef parse_options\n index = -1\n while loop_cond\n index += 1\n\n item = command_line.args[index]\n if option\n index += 1\n else\n option = foo(item)\n if option\n index += 1\n else\n option = bar(item)\n if option\n index += 1\n end\n end\n end\n end\nend\n```\n```\n❯ git rev-parse HEAD\neb470cef93cacb1e8806c6202e976d5693f91b3d\n\n❯ rm -rf /home/josh/.cache/rubocop_cache\n\n❯ bundle exec rubocop --debug --only Lint/UselessAssignment example.rb\nFor /home/josh/work/rubocop: configuration from /home/josh/work/rubocop/.rubocop.yml\nDefault configuration from /home/josh/work/rubocop/config/default.yml\nPlugin configuration from /home/josh/work/rubocop/config/internal_affairs.yml\nPlugin configuration from /home/josh/.rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/rubocop-performance-1.25.0/config/default.yml\nPlugin configuration from /home/josh/.rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/rubocop-rake-0.7.1/config/default.yml\nPlugin configuration from /home/josh/.rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/rubocop-rspec-3.6.0/config/default.yml\nInheriting configuration from /home/josh/work/rubocop/.rubocop_todo.yml\nUse parallel by default.\nSkipping parallel inspection: only a single file needs inspection\nInspecting 1 file\nScanning /home/josh/work/rubocop/example.rb\nW\n\nOffenses:\n\nexample.rb:8:7: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - index.\n index += 1\n ^^^^^\nexample.rb:12:9: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - index.\n index += 1\n ^^^^^\n\n1 file inspected, 2 offenses detected, 2 offenses autocorrectable\nFinished in 0.25948607735335827 seconds\n```\n\n## RuboCop version\n\n```\n❯ bundle exec rubocop -V \n1.79.1 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.2.5) [x86_64-linux]\n - rubocop-performance 1.25.0\n - rubocop-rake 0.7.1\n - rubocop-rspec 3.6.0\n\n```","author":{"url":"https://github.com/joshcooper","@type":"Person","name":"joshcooper"},"datePublished":"2025-08-04T17:02:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/14419/rubocop/issues/14419"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:90e9e59e-2480-68a0-5f2d-91b6027f1387 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D30E:53AD4:2DCC81:3AF3F1:69951323 |
| html-safe-nonce | 278b9687ec715f1449cf5fe0e2bde04da555c71518cca454c288cfcfff079351 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzBFOjUzQUQ0OjJEQ0M4MTozQUYzRjE6Njk5NTEzMjMiLCJ2aXNpdG9yX2lkIjoiNjU4MTI2MjE3NTY1NDE4NzgxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 87cbb2b77bd0aee418a799c209eff572822ec2ca9c5dcbdeaf748c643f8eab63 |
| hovercard-subject-tag | issue:3290175812 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/rubocop/rubocop/14419/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b33d94378414b823e7050b04f8092493bc2e0eab6accaca6d0c5f7300f71d365/rubocop/rubocop/issues/14419 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b33d94378414b823e7050b04f8092493bc2e0eab6accaca6d0c5f7300f71d365/rubocop/rubocop/issues/14419 |
| og:image:alt | Lint/UselessAssignment reports false positives even after 1.79.1 and #14409 Expected behavior rubocop should not report a violation Actual behavior Rubocop reports lines 8 and 12 are useless assign... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joshcooper |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4bd759bc5f83244e2a0de29b937365905c0fefd238b6f077c24a49830375b4df |
| turbo-cache-control | no-preview |
| go-import | github.com/rubocop/rubocop git https://github.com/rubocop/rubocop.git |
| octolytics-dimension-user_id | 10871348 |
| octolytics-dimension-user_login | rubocop |
| octolytics-dimension-repository_id | 4095287 |
| octolytics-dimension-repository_nwo | rubocop/rubocop |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 4095287 |
| octolytics-dimension-repository_network_root_nwo | rubocop/rubocop |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cac7d4a5a6053f6655d0c3e8bfe5fd7a55c216fd |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width