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 #9011] Mark Lint/Loop as unsafe #9028

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

dvandersluis
Copy link
Member

The case in #9011

loop do
  key = generate_key
  break if some_check?
end

puts key

cannot be detected by static analysis, so instead I've marked autocorrection for Lint/Loop as unsafe and added an explanation.


Before submitting the PR make sure the following are checked:

  • 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.
  • 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.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@marcandre
Copy link
Contributor

cannot be detected by static analysis

Are you sure?

Also, like I wrote in #9008, loop rescues StopIteration, so it's never strictly equivalent.

@dvandersluis
Copy link
Member Author

@marcandre I was simplifying, we could I suppose detect every lvar in the begin and look for it in the following code but there are always edge cases and I don’t think it’s worthwhile.

Didn’t know about StopIteration but then that’s another reason to make it unsafe. I can change it to be unsafe as a whole and not just for autocorrection.

@marcandre
Copy link
Contributor

marcandre commented Nov 12, 2020

I can change it to be unsafe as a whole and not just for autocorrection.

Probably the most accurate thing to do, however unlikely it is to affect someone.

@dvandersluis
Copy link
Member Author

Updated!

@marcandre marcandre merged commit e299edd into rubocop:master Nov 12, 2020
@marcandre
Copy link
Contributor

Thanks!

@dvandersluis dvandersluis changed the title [Fix #9011] Mark autocorrection for Lint/Loop as unsafe [Fix #9011] Mark Lint/Loop as unsafe Nov 12, 2020
@dvandersluis dvandersluis deleted the issue/9011 branch January 18, 2021 20:42
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.

None yet

2 participants