@@ -16,7 +16,6 @@ module Rails
16
16
# And `compact_blank!` has different implementations for `Array`, `Hash`, and
17
17
# `ActionController::Parameters`.
18
18
# `Array#compact_blank!`, `Hash#compact_blank!` are equivalent to `delete_if(&:blank?)`.
19
- # `ActionController::Parameters#compact_blank!` is equivalent to `reject!(&:blank?)`.
20
19
# If the cop makes a mistake, autocorrected code may get unexpected behavior.
21
20
#
22
21
# @example
@@ -33,8 +32,6 @@ module Rails
33
32
# # bad
34
33
# collection.delete_if(&:blank?) # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
35
34
# collection.delete_if { |_k, v| v.blank? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
36
- # collection.reject!(&:blank?) # Same behavior as `ActionController::Parameters#compact_blank!`
37
- # collection.reject! { |_k, v| v.blank? } # Same behavior as `ActionController::Parameters#compact_blank!`
38
35
# collection.keep_if(&:present?) # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
39
36
# collection.keep_if { |_k, v| v.present? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
40
37
#
@@ -47,20 +44,20 @@ class CompactBlank < Base
47
44
extend TargetRailsVersion
48
45
49
46
MSG = 'Use `%<preferred_method>s` instead.'
50
- RESTRICT_ON_SEND = %i[ reject delete_if reject! select keep_if ] . freeze
47
+ RESTRICT_ON_SEND = %i[ reject delete_if select keep_if ] . freeze
51
48
52
49
minimum_target_rails_version 6.1
53
50
54
51
def_node_matcher :reject_with_block? , <<~PATTERN
55
52
(block
56
- (send _ {:reject :delete_if :reject! })
53
+ (send _ {:reject :delete_if})
57
54
$(args ...)
58
55
(send
59
56
$(lvar _) :blank?))
60
57
PATTERN
61
58
62
59
def_node_matcher :reject_with_block_pass? , <<~PATTERN
63
- (send _ {:reject :delete_if :reject! }
60
+ (send _ {:reject :delete_if}
64
61
(block_pass
65
62
(sym :blank?)))
66
63
PATTERN
0 commit comments