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

Mark Style/InfiniteLoop as unsafe #9008

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_mark_styleinfiniteloop_as_unsafe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9008](https://github.com/rubocop-hq/rubocop/pull/9008): Mark `Style/InfiniteLoop` as unsafe. ([@marcandre][])
6 changes: 4 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3356,12 +3356,14 @@ Style/ImplicitRuntimeError:
VersionAdded: '0.41'

Style/InfiniteLoop:
Description: 'Use Kernel#loop for infinite loops.'
Description: >-
Use Kernel#loop for infinite loops.
This cop is unsafe in the body may raise a `StopIteration` exception.
Safe: false
StyleGuide: '#infinite-loop'
Enabled: true
VersionAdded: '0.26'
VersionChanged: '0.61'
SafeAutoCorrect: true

Style/InlineComment:
Description: 'Avoid trailing inline comments.'
Expand Down
8 changes: 6 additions & 2 deletions docs/modules/ROOT/pages/cops_style.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4602,14 +4602,18 @@ raise ArgumentError, 'Error message here'
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Enabled
| Yes
| Yes
| No
| Yes (Unsafe)
| 0.26
| 0.61
|===

Use `Kernel#loop` for infinite loops.

This cop is marked as unsafe as the rule does not necessarily
apply if the body might raise a `StopIteration` exception; contrary to
other infinite loops, `Kernel#loop` silently rescues that and returns `nil`.

=== Examples

[source,ruby]
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/style/infinite_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Cop
module Style
# Use `Kernel#loop` for infinite loops.
#
# This cop is marked as unsafe as the rule does not necessarily
# apply if the body might raise a `StopIteration` exception; contrary to
# other infinite loops, `Kernel#loop` silently rescues that and returns `nil`.
#
# @example
# # bad
# while true
Expand Down