Skip to content

Commit

Permalink
Mark Style/InfiniteLoop as unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Nov 8, 2020
1 parent 0c2151d commit d163460
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
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 @@ -3362,12 +3362,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

0 comments on commit d163460

Please sign in to comment.