rubocop-rails 2.35.1 → 2.35.3

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: 409bf447cc0d5a3b6529407611f53ad1331a5c1bd908e35b7f50193e53bb2c95
4
- data.tar.gz: 5d3b83383d138616bcfbbe292413f6ddd6f49b60be33dbe57fdcd481bb7d1c1c
3
+ metadata.gz: a93c373c0dc8f85fb3b81807cd6971588d148c6f02f4baac770c4a842cd59281
4
+ data.tar.gz: b54098494c0900a297281fed2eb634e38867ed0e3e14f84536765d9ccdc8ed6d
5
5
  SHA512:
6
- metadata.gz: ea50f3fad3d83f62ec110dd0a5b32688f92fcd0963d486714e4a71867343316b67842476f67dd64a5c6d7ccde5f43aeca5c1980ec20e96f097703fdf6ad7c15c
7
- data.tar.gz: eb75cb4c5b5a21562ff42dd194fea691e2feec9563095a1a1509b3263a41693ce072a075a269e1416c8f150cf201a602e2301ac1d993dc7a237c3bbe19083d04
6
+ metadata.gz: 9d3a419adf9b427d3cba678db098a08a0bbc69b8e7c5ec668108bede4217bdff67f1b8724e22e674ad653e2512dcb49483933f4b064d3f46a4c676d179bb0265
7
+ data.tar.gz: e2da63cb8261679f1fd9333f78ef278fc46bd2f06120a66b1ff8f4ddde1562f008f07246cea76cd0cb67ed8ba44c5e575493a44bc9ef43e9050f2258f0039c72
@@ -9,7 +9,9 @@ module RuboCop
9
9
  # and the cop detects it using the `expect` method.
10
10
  #
11
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?`), or key-check methods such as `key?`
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)`
13
15
  # - Passing `params[:key]` as an argument to finder methods that raise on missing records
14
16
  # - Strong parameter methods using `require` or `permit`
15
17
  #
@@ -54,9 +56,18 @@ module RuboCop
54
56
 
55
57
  MSG = 'Use `%<prefer>s` instead.'
56
58
  RESTRICT_ON_SEND = %i[[] require permit].freeze
57
- PRESENCE_CHECK_METHODS = %i[nil? blank? present? presence].freeze
58
- NIL_SAFE_METHODS = %i[instance_of? is_a? kind_of? to_a to_f to_h to_i to_s].freeze
59
- KEY_CHECK_METHODS = %i[key? has_key? include? member?].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
60
71
  RAISING_FINDER_METHODS = %i[find find_by! find_sole_by].freeze
61
72
 
62
73
  minimum_target_rails_version 8.0
@@ -130,17 +141,15 @@ module RuboCop
130
141
  def offensive_bracket_access?(node)
131
142
  return false unless (parent = node.parent)
132
143
  return false if parent.or_type?
144
+ return false if parent.csend_type? && parent.receiver == node
133
145
  return true if parent.each_ancestor(:call).any? { |node| raising_finder_method?(node) }
134
146
  return false unless parent.call_type?
135
147
 
136
148
  if parent.receiver == node
137
149
  return false if parent.comparison_method? || parent.method?(:[])
150
+ return false if block_call?(parent)
138
151
 
139
- method_name = parent.method_name
140
-
141
- !PRESENCE_CHECK_METHODS.include?(method_name) &&
142
- !NIL_SAFE_METHODS.include?(method_name) &&
143
- !KEY_CHECK_METHODS.include?(method_name)
152
+ !IGNORED_METHODS.include?(parent.method_name)
144
153
  else
145
154
  raising_finder_method?(parent)
146
155
  end
@@ -151,6 +160,10 @@ module RuboCop
151
160
  RAISING_FINDER_METHODS.include?(node.method_name)
152
161
  end
153
162
 
163
+ def block_call?(send_node)
164
+ send_node.block_literal? || send_node.last_argument&.block_pass_type?
165
+ end
166
+
154
167
  def offense_range(method_node, node)
155
168
  method_node.loc.selector.join(node.source_range.end)
156
169
  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.1'
7
+ STRING = '2.35.3'
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.1
4
+ version: 2.35.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov