-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix a false positive for Lint/UselessAssignment #14377
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 a false positive for Lint/UselessAssignment #14377
Conversation
|
Can you rebase with the latest master branch? |
7011783 to
7ee22fb
Compare
|
I rebased on the latest master branch and corrected my commit history. |
| RUBY | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be false positives with case-match?
| end | |
| end | |
| context 'when duplicate assignments in a case-match branch inside a loop', :ruby27 do | |
| context 'while loop' do | |
| it 'does not register an offense' do | |
| expect_no_offenses(<<~RUBY) | |
| while | |
| case expr | |
| in fizz then foo += 1 | |
| in buzz then foo -= 1 | |
| end | |
| end | |
| RUBY | |
| end | |
| end | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's necessary as well. I've added it. Thank you.
lib/rubocop/cop/variable_force.rb
Outdated
| def reference_assignments(loop_assignments, node) | ||
| # If inside a case statement, mark all as referenced. | ||
| # Otherwise, mark only the last assignment as referenced. | ||
| if loop_assignments.first.node.each_ancestor(:case).any? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to account for case-match?
| if loop_assignments.first.node.each_ancestor(:case).any? | |
| if loop_assignments.first.node.each_ancestor(:case, :case_match).any? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's necessary as well. I've added it. Thank you.
7ee22fb to
bfe8ff3
Compare
|
Thanks! |
Fixes rubocop/rubocop-jp#15. (This link is Japanese issue)
This PR fixes a false positive for
Lint/UselessAssignmentwhen the assignment is inside a loop body.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.