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

Lint/AssignmentInCondition giving false positives in block-in-condition #10136

Closed
ccutrer opened this issue Sep 28, 2021 · 0 comments · Fixed by #10137
Closed

Lint/AssignmentInCondition giving false positives in block-in-condition #10136

ccutrer opened this issue Sep 28, 2021 · 0 comments · Fixed by #10137
Labels

Comments

@ccutrer
Copy link
Contributor

ccutrer commented Sep 28, 2021

The file in the reproduction steps section shouldn't report any errors for this linter.

Expected behavior

No offenses are shown for this code.

Actual behavior

rubocop --debug --only Lint/AssignmentInCondition -- test.rb

gives

For /Users/cody/src/inst-jobs: configuration from /Users/cody/src/inst-jobs/.rubocop.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rails-2.12.2/config/default.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rails-2.12.2/config/default.yml
Default configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-1.21.0/config/default.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rspec-2.5.0/config/default.yml
configuration from /Users/cody/.gem/ruby/2.7.2/gems/rubocop-rspec-2.5.0/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /Users/cody/.cache/rubocop_cache/c6e7bb119f0c0f52ccd63d4e1409d8a6f230f3ab/62a2053d41eb97fee50d7702bbb1b9ef8ecff8a4/6c68e4455f826a7733bbff3337b441b66287c5af
Inspecting 1 file
Scanning /Users/cody/src/inst-jobs/test.rb
Loading cache from /Users/cody/.cache/rubocop_cache/c6e7bb119f0c0f52ccd63d4e1409d8a6f230f3ab/62a2053d41eb97fee50d7702bbb1b9ef8ecff8a4/6c68e4455f826a7733bbff3337b441b66287c5af
W

Offenses:

test.rb:2:42: W: Lint/AssignmentInCondition: Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
                              submission = @gradebook_importer_assignments[student.id][idx]
                                         ^
test.rb:6:51: W: Lint/AssignmentInCondition: Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
                              submission['grade'] = 'EX' if submission['grade'].to_s.casecmp('EX') == 0
                                                  ^
test.rb:7:41: W: Lint/AssignmentInCondition: Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
                              no_change = no_change_to_submission?(submission)
                                        ^
test.rb:9:92: W: Lint/AssignmentInCondition: Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
                              @warning_messages[:prevented_grading_ungradeable_submission] =
                                                                                           ^

1 file inspected, 4 offenses detected
Finished in 0.7389060000423342 seconds

Steps to reproduce the problem

test.rb:

indexes_to_delete << idx if readonly_assignment?(assignment) || @students.all? do |student|
                              submission = @gradebook_importer_assignments[student.id][idx]

                              # Have potentially mixed case excused in grade match case
                              # expectations for the compare so it doesn't look changed
                              submission['grade'] = 'EX' if submission['grade'].to_s.casecmp('EX') == 0
                              no_change = no_change_to_submission?(submission)

                              @warning_messages[:prevented_grading_ungradeable_submission] =
                                true if !submission['gradeable'] && !no_change

                              no_change || !submission['gradeable']
                            end

RuboCop version

1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 2.7.2 x86_64-darwin20)
  - rubocop-rails 2.12.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.5.0
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 29, 2021
…er assignments within blocks in conditions.
koic added a commit that referenced this issue Sep 29, 2021
[Fix #10136] Update `Lint/AssignmentInCondition` to not consider assignments within blocks in conditions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants