Skip to content
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

[Fix #13309] Fix false negative with Lint/UselessAssignment when an useless assignment exists followed by a block #13389

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

pCosta99
Copy link
Contributor

Similar example false negative situation pointed in issue #13309 :

foo = 1 # should have an offense
foo = 2
bar {
  foo = 3
}

The issue here is that Lint/UselessAssignment checks if assignments have been used, however, the assignments check it based on the assignment having been referenced or the variable being used in a block. So, the false negative occurs because of the first assignment being unused but having the variable captured in a block. One potential way of solving this is too track reassignments (a new assignment follows a not referenced assignment).

Fixes #13309.


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.

@@ -0,0 +1 @@
* [#13309](https://github.com/rubocop/rubocop/issues/13309): Fix and spec false negative for `Lint/UselessAssignment` cop when there is an useless assignment followed by a block. ([@pCosta99][])
Copy link
Member

Choose a reason for hiding this comment

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

Can you update it to the following text?

Suggested change
* [#13309](https://github.com/rubocop/rubocop/issues/13309): Fix and spec false negative for `Lint/UselessAssignment` cop when there is an useless assignment followed by a block. ([@pCosta99][])
* [#13309](https://github.com/rubocop/rubocop/issues/13309): Fix a false negative for `Lint/UselessAssignment` cop when there is a useless assignment followed by a block. ([@pCosta99][])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! 👍

@koic koic merged commit 8d66aad into rubocop:master Oct 26, 2024
22 checks passed
@koic
Copy link
Member

koic commented Oct 26, 2024

Thanks!

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.

False negative for Lint/UselessAssignment
2 participants