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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a93c373c0dc8f85fb3b81807cd6971588d148c6f02f4baac770c4a842cd59281
4
- data.tar.gz: b54098494c0900a297281fed2eb634e38867ed0e3e14f84536765d9ccdc8ed6d
3
+ metadata.gz: 45b000a9e63ce4154fb6b1acbb97c84253448ead8bac7539aa773dbc1a7e3f8b
4
+ data.tar.gz: 26646956ab4da49c53a4d9105771e83658b07c65912799e5eea7f4d88e5f399f
5
5
  SHA512:
6
- metadata.gz: 9d3a419adf9b427d3cba678db098a08a0bbc69b8e7c5ec668108bede4217bdff67f1b8724e22e674ad653e2512dcb49483933f4b064d3f46a4c676d179bb0265
7
- data.tar.gz: e2da63cb8261679f1fd9333f78ef278fc46bd2f06120a66b1ff8f4ddde1562f008f07246cea76cd0cb67ed8ba44c5e575493a44bc9ef43e9050f2258f0039c72
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
- $(call
97
+ [
81
98
  $(call
82
- (send nil? :params) :require _) :permit _+)
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
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.35.3'
7
+ STRING = '2.35.4'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.35.3
4
+ version: 2.35.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov