Skip to content

[Fix #14445] Fix false positives for Lint/UselessAssignment with for loops when the variable is referenced in the collection #14458

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

Merged
merged 1 commit into from
Aug 18, 2025

Conversation

Earlopain
Copy link
Contributor

Fix #14445

In a for-style loop, the children don't appear in the order that they actually execute.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -243,6 +243,11 @@ def process_loop(node)
condition_node, body_node = *node
process_node(body_node)
process_node(condition_node)
elsif node.for_type?
# In `for foo in bar` the rightmost expression is evaluated first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just my two cents:

Suggested change
# In `for foo in bar` the rightmost expression is evaluated first
# In `for item in items` the rightmost expression is evaluated first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I changed it

@Earlopain Earlopain force-pushed the useless-assignment-for-loop branch 2 times, most recently from 27eea08 to 4f8b2a4 Compare August 18, 2025 09:58
…with `for` loops when the variable is referenced in the collection

In a for-style loop, the children don't appear in the order that they actually execute.
@Earlopain Earlopain force-pushed the useless-assignment-for-loop branch from 4f8b2a4 to 1231fea Compare August 18, 2025 10:04
@koic koic merged commit 8106e26 into rubocop:master Aug 18, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint/UselessAssignment must be considered unsafe
2 participants