You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new Style/CollectionCompact cop may change some code behavior. It assumes that reject can be replaced with compact even when it shouldn't. Probably it is applying to an Array#reject a correction that would only be valid for a Hash#reject. See below for an example.
Expected behavior
When a reject method is called for an array with a block with two arguments, and this block only checks if the second argument is nil, this reject shouldn't be replaced with a compact.
Actual behavior
reject gets replaced with compact in that scenario.
Fixesrubocop#9023.
This PR marks unsafe for `Style/CollectionCompact` by default because
false positives may occur in the nil check of block arguments to the
receiver object.
For example, `[[1, 2], [3, nil]].reject { |first, second| second.nil? }`
and `[[1, 2], [3, nil]].compact` are not compatible. This will work fine
when the receiver is a hash object.
The new
Style/CollectionCompact
cop may change some code behavior. It assumes thatreject
can be replaced withcompact
even when it shouldn't. Probably it is applying to anArray#reject
a correction that would only be valid for aHash#reject
. See below for an example.Expected behavior
When a
reject
method is called for an array with a block with two arguments, and this block only checks if the second argument is nil, thisreject
shouldn't be replaced with acompact
.Actual behavior
reject
gets replaced withcompact
in that scenario.Steps to reproduce the problem
test.rb
):RuboCop version
The text was updated successfully, but these errors were encountered: