rubocop-rails 2.35.3 → 2.35.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/rails/strong_parameters_expect.rb +23 -3
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 45b000a9e63ce4154fb6b1acbb97c84253448ead8bac7539aa773dbc1a7e3f8b
|
|
4
|
+
data.tar.gz: 26646956ab4da49c53a4d9105771e83658b07c65912799e5eea7f4d88e5f399f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8e1594a6edae31940c736c45a37966d09d02ada59afad3146b8941c4668b500c288e30da7293ae34d6ee38d1e2fc47b69900c8afa8f7e598da92e91d55f4d46
|
|
7
|
+
data.tar.gz: 15994ecea386276d46a19c17ec5bc962138a1476b4508f36353a9fb10e20f6fb30a1b1d78f837d9beef9980103a9786160d50b1fc610f06a092bc874b9621050
|
|
@@ -23,6 +23,18 @@ module RuboCop
|
|
|
23
23
|
# incompatibility introduced for valid reasons by the `expect` method, which aligns better with
|
|
24
24
|
# strong parameter conventions.
|
|
25
25
|
#
|
|
26
|
+
# It is also unsafe because `expect` is stricter about the structure of the parameters than
|
|
27
|
+
# `require`/`permit`. Nested attributes that hold an array of records need an extra array wrapper,
|
|
28
|
+
# such as `expect(user: [{ pets_attributes: [[:name]] }])`. The cop cannot tell a single nested hash
|
|
29
|
+
# from an array of nested hashes, so it always generates the single-hash form, which can turn
|
|
30
|
+
# a previously successful request into a failure.
|
|
31
|
+
#
|
|
32
|
+
# It is also unsafe when `params[:key]` is passed to a finder method such as `find`, because
|
|
33
|
+
# `find` accepts an array of IDs. `Model.find(params[:id])` loads every record for an array of IDs,
|
|
34
|
+
# but the corrected `Model.find(params.expect(:id))` raises `ActionController::ParameterMissing`
|
|
35
|
+
# for an array value, since `expect` requires a scalar. The cop cannot tell a scalar ID from
|
|
36
|
+
# an array of IDs, so the autocorrection can turn a previously successful request into a failure.
|
|
37
|
+
#
|
|
26
38
|
# @example
|
|
27
39
|
#
|
|
28
40
|
# # bad
|
|
@@ -62,7 +74,7 @@ module RuboCop
|
|
|
62
74
|
IGNORED_METHODS = %i[
|
|
63
75
|
! blank? compact compact! compact_blank compact_blank! deep_merge deep_merge!
|
|
64
76
|
delete delete_if dig each except exclude? extract! fetch has_key? has_value?
|
|
65
|
-
include? instance_of? is_a? keep_if key? keys kind_of? member? merge merge!
|
|
77
|
+
include? inspect instance_of? is_a? keep_if key? keys kind_of? member? merge merge!
|
|
66
78
|
nil? presence present? reverse_merge reverse_merge! slice stringify_keys
|
|
67
79
|
to_a to_f to_h to_hash to_i to_s to_unsafe_h to_unsafe_hash
|
|
68
80
|
transform_keys transform_keys! transform_values transform_values! try try!
|
|
@@ -76,10 +88,18 @@ module RuboCop
|
|
|
76
88
|
(send (send nil? :params) :[] $_)
|
|
77
89
|
PATTERN
|
|
78
90
|
|
|
91
|
+
# `require` with an array literal expects multiple top-level keys and has no single `expect` equivalent,
|
|
92
|
+
# so such calls are excluded to avoid generating broken code.
|
|
93
|
+
# A single dynamic argument to `permit` (such as a method call or variable that may return an array)
|
|
94
|
+
# has no safe `expect` rewrite, because the cop cannot tell whether the value is a list of attributes
|
|
95
|
+
# or a nested hash. Such calls are excluded to avoid generating broken code.
|
|
79
96
|
def_node_matcher :params_require_permit, <<~PATTERN
|
|
80
|
-
|
|
97
|
+
[
|
|
81
98
|
$(call
|
|
82
|
-
(
|
|
99
|
+
$(call
|
|
100
|
+
(send nil? :params) :require !array) :permit _+)
|
|
101
|
+
!(call _ :permit {call lvar ivar cvar gvar const})
|
|
102
|
+
]
|
|
83
103
|
PATTERN
|
|
84
104
|
|
|
85
105
|
def_node_matcher :params_permit_require, <<~PATTERN
|