File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change
1
+ * [ #826 ] ( https://github.com/rubocop/rubocop-rails/issues/826 ) : Mark ` Rails/Pluck ` as unsafe. ([ @fatkodima ] [ ] )
Original file line number Diff line number Diff line change @@ -687,7 +687,9 @@ Rails/Pluck:
687
687
Description : ' Prefer `pluck` over `map { ... }`.'
688
688
StyleGuide : ' https://rails.rubystyle.guide#pluck'
689
689
Enabled : ' pending'
690
+ Safe : false
690
691
VersionAdded : ' 2.7'
692
+ VersionChanged : ' <<next>>'
691
693
692
694
Rails/PluckId :
693
695
Description : ' Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
Original file line number Diff line number Diff line change @@ -9,6 +9,22 @@ module Rails
9
9
# element in an enumerable. When called on an Active Record relation, it
10
10
# results in a more efficient query that only selects the necessary key.
11
11
#
12
+ # @safety
13
+ # This cop is unsafe because model can define attribute aliases.
14
+ #
15
+ # [source,ruby]
16
+ # ----
17
+ # class User < ApplicationRecord
18
+ # alias_attribute :nickname, :name
19
+ # end
20
+ #
21
+ # # Original code
22
+ # User.map { |user| user[:nickname] } # => array of nicknames
23
+ #
24
+ # # After autocorrection
25
+ # User.pluck(:nickname) # => raises ActiveRecord::StatementInvalid
26
+ # ----
27
+ #
12
28
# @example
13
29
# # bad
14
30
# Post.published.map { |post| post[:title] }
You can’t perform that action at this time.
0 commit comments