Skip to content

Commit 9ac7a15

Browse files
authored
Merge pull request #972 from koic/mark_rails_find_each_as_unsafe
[Fix #694] Mark `Rails/FindEach` as unsafe
2 parents ce3abde + f5aa590 commit 9ac7a15

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#694](https://github.com/rubocop/rubocop-rails/issues/694): Mark `Rails/FindEach` as unsafe. ([@koic][])

config/default.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,9 @@ Rails/FindEach:
460460
Description: 'Prefer all.find_each over all.each.'
461461
StyleGuide: 'https://rails.rubystyle.guide#find-each'
462462
Enabled: true
463+
Safe: false
463464
VersionAdded: '0.30'
464-
VersionChanged: '2.9'
465+
VersionChanged: '<<next>>'
465466
Include:
466467
- app/models/**/*.rb
467468
AllowedMethods:

lib/rubocop/cop/rails/find_each.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
module RuboCop
44
module Cop
55
module Rails
6-
# Identifies usages of `all.each` and
7-
# change them to use `all.find_each` instead.
6+
# Identifies usages of `all.each` and change them to use `all.find_each` instead.
7+
#
8+
# @safety
9+
# This cop is unsafe if the receiver object is not an Active Record object.
10+
# Also, `all.each` returns an `Array` instance and `all.find_each` returns nil,
11+
# so the return values are different.
812
#
913
# @example
1014
# # bad

0 commit comments

Comments
 (0)