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

False Positive on Lint/LiteralAssignmentInCondition #12434

Closed
ccutrer opened this issue Dec 1, 2023 · 0 comments · Fixed by #12438
Closed

False Positive on Lint/LiteralAssignmentInCondition #12434

ccutrer opened this issue Dec 1, 2023 · 0 comments · Fixed by #12438
Labels

Comments

@ccutrer
Copy link
Contributor

ccutrer commented Dec 1, 2023

Expected behavior

Lint/LiteralAssignmentInCondition should not register for non-literals

Actual behavior

A string with interpolation in the condition of a loop where the interpolation values change inside is triggering the cop.

Steps to reproduce the problem

# frozen_string_literal: true

def my_method
  until block.call(new_name = "#{dir}#{basename}-#{addition}#{extname}")
    addition += 1
    return random_backup_name if addition >= 8
  end
  new_name
end

rubocop --only Lint/LiteralAssignmentInCondition test.rb

RuboCop version

% rubocop -V
1.58.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.1.3) [arm64-darwin21]
@koic koic added the bug label Dec 2, 2023
koic added a commit to koic/rubocop that referenced this issue Dec 2, 2023
…nCondition`

Fixes rubocop#12434.

This PR fixes a false positive for `Lint/LiteralAssignmentInCondition`
when using interpolated string or xstring literals.
koic added a commit that referenced this issue Dec 9, 2023
…eral_assignment_in_condition

[Fix #12434] Fix a false positive for `Lint/LiteralAssignmentInCondition`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants