rubocop-rails 2.35.0 → 2.35.2

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: e4946e79ccf9661248df014d69703665df3b0a72aa800e8c456afc59594ad944
4
- data.tar.gz: 7575ea946eb4e6985d6c0c365a0f39345fc6d32b0634c74949526f987d1ac38d
3
+ metadata.gz: e7ef7ef7c6866ef07a53db5870b5a0aa169656ad1235015a6ab1c9eeef58e5ad
4
+ data.tar.gz: 533c4f378c36a4da9e9bbe402884a6137a3150807785ec586907366307591aee
5
5
  SHA512:
6
- metadata.gz: 7a660eb16537b1dafe092cb100229fd9f039f8d98b51e1408b9438997176c8fc0fde61494ae462bfa8ea15e65524f5ec99e4d2efac42d0461395da65bfe8cb8b
7
- data.tar.gz: ad601bb6b3296dceb196159604975b5e2efecaca5c66f715523368344f8a77e62d93cf8e22c4b3d53ce67d849a34cf9a1f4d184d6b655ecea0f12da23490bb35
6
+ metadata.gz: 577e541755bd86dedfe380196f3526db764b350aad31b4503da926216b67643260507375ec7e8270cc1a8652a8a1c2742b0439275c732b93680512d8e2a39d08
7
+ data.tar.gz: e414a5bf1b501de2af27979b5cb346bbc8ad5105a74e455c7409fcd7463974cbcba97c0bbe2b1bfb99a598e3a8741a7f92dba27f1bd7c5cc4f4b799a19476aa5
@@ -12,7 +12,7 @@ module RuboCop
12
12
  # which can affect their behavior.
13
13
  #
14
14
  # @safety
15
- # This cop is unsafe for autocorrection if the receiver for `all` is not an Active Record object.
15
+ # This cop is unsafe because false positives will occur if the receiver is not an Active Record object.
16
16
  #
17
17
  # @example
18
18
  # # bad
@@ -8,7 +8,10 @@ module RuboCop
8
8
  # In the following cases, `params[:key]` is treated as a key that is expected to be passed from the HTTP client,
9
9
  # and the cop detects it using the `expect` method.
10
10
  #
11
- # - Method calls on `params[:key]` without comparison methods
11
+ # - Method calls on `params[:key]` without comparison methods, methods that are safe to call
12
+ # on `nil` (such as `to_i`, `to_s`, or `is_a?`), key-check methods such as `key?`,
13
+ # collection methods such as `keys`, `merge`, or `slice`, or block-style calls such as
14
+ # `params[:key].each { ... }` or `params[:key].map(&:to_s)`
12
15
  # - Passing `params[:key]` as an argument to finder methods that raise on missing records
13
16
  # - Strong parameter methods using `require` or `permit`
14
17
  #
@@ -53,7 +56,18 @@ module RuboCop
53
56
 
54
57
  MSG = 'Use `%<prefer>s` instead.'
55
58
  RESTRICT_ON_SEND = %i[[] require permit].freeze
56
- PRESENCE_CHECK_METHODS = %i[nil? blank? present? presence].freeze
59
+ # Method calls on `params[:key]` that should not be rewritten with `expect(:key)`.
60
+ # Covers presence/nil checks, nil-safe conversions and type checks, key-check methods,
61
+ # and collection methods that imply `params[:key]` is a Hash/Array.
62
+ IGNORED_METHODS = %i[
63
+ blank? compact compact! compact_blank compact_blank! deep_merge deep_merge!
64
+ 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!
66
+ nil? presence present? reverse_merge reverse_merge! slice stringify_keys
67
+ to_a to_f to_h to_hash to_i to_s to_unsafe_h to_unsafe_hash
68
+ transform_keys transform_keys! transform_values transform_values! try try!
69
+ value? values values_at with_defaults with_defaults! without
70
+ ].freeze
57
71
  RAISING_FINDER_METHODS = %i[find find_by! find_sole_by].freeze
58
72
 
59
73
  minimum_target_rails_version 8.0
@@ -131,9 +145,10 @@ module RuboCop
131
145
  return false unless parent.call_type?
132
146
 
133
147
  if parent.receiver == node
134
- return false if parent.comparison_method?
148
+ return false if parent.comparison_method? || parent.method?(:[])
149
+ return false if block_call?(parent)
135
150
 
136
- !parent.method?(:[]) && !PRESENCE_CHECK_METHODS.include?(parent.method_name)
151
+ !IGNORED_METHODS.include?(parent.method_name)
137
152
  else
138
153
  raising_finder_method?(parent)
139
154
  end
@@ -144,6 +159,10 @@ module RuboCop
144
159
  RAISING_FINDER_METHODS.include?(node.method_name)
145
160
  end
146
161
 
162
+ def block_call?(send_node)
163
+ send_node.block_literal? || send_node.last_argument&.block_pass_type?
164
+ end
165
+
147
166
  def offense_range(method_node, node)
148
167
  method_node.loc.selector.join(node.source_range.end)
149
168
  end
@@ -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.0'
7
+ STRING = '2.35.2'
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.0
4
+ version: 2.35.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov