rubocop-rails 2.35.0 → 2.35.1

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: 409bf447cc0d5a3b6529407611f53ad1331a5c1bd908e35b7f50193e53bb2c95
4
+ data.tar.gz: 5d3b83383d138616bcfbbe292413f6ddd6f49b60be33dbe57fdcd481bb7d1c1c
5
5
  SHA512:
6
- metadata.gz: 7a660eb16537b1dafe092cb100229fd9f039f8d98b51e1408b9438997176c8fc0fde61494ae462bfa8ea15e65524f5ec99e4d2efac42d0461395da65bfe8cb8b
7
- data.tar.gz: ad601bb6b3296dceb196159604975b5e2efecaca5c66f715523368344f8a77e62d93cf8e22c4b3d53ce67d849a34cf9a1f4d184d6b655ecea0f12da23490bb35
6
+ metadata.gz: ea50f3fad3d83f62ec110dd0a5b32688f92fcd0963d486714e4a71867343316b67842476f67dd64a5c6d7ccde5f43aeca5c1980ec20e96f097703fdf6ad7c15c
7
+ data.tar.gz: eb75cb4c5b5a21562ff42dd194fea691e2feec9563095a1a1509b3263a41693ce072a075a269e1416c8f150cf201a602e2301ac1d993dc7a237c3bbe19083d04
@@ -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,8 @@ 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?`), or key-check methods such as `key?`
12
13
  # - Passing `params[:key]` as an argument to finder methods that raise on missing records
13
14
  # - Strong parameter methods using `require` or `permit`
14
15
  #
@@ -54,6 +55,8 @@ module RuboCop
54
55
  MSG = 'Use `%<prefer>s` instead.'
55
56
  RESTRICT_ON_SEND = %i[[] require permit].freeze
56
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
57
60
  RAISING_FINDER_METHODS = %i[find find_by! find_sole_by].freeze
58
61
 
59
62
  minimum_target_rails_version 8.0
@@ -131,9 +134,13 @@ module RuboCop
131
134
  return false unless parent.call_type?
132
135
 
133
136
  if parent.receiver == node
134
- return false if parent.comparison_method?
137
+ return false if parent.comparison_method? || parent.method?(:[])
135
138
 
136
- !parent.method?(:[]) && !PRESENCE_CHECK_METHODS.include?(parent.method_name)
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)
137
144
  else
138
145
  raising_finder_method?(parent)
139
146
  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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov