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
I expect this cop to only apply to Array select and not to Hash select.
Actual behavior
Hash select is flagged if the arity is 1, even though the suggested autocorrect is wrong. i.e. hash.select {|k| /foo/.match? k } can't be replaced with hash.grep(/foo/), since single-arg grep always returns [] with hashes.
Steps to reproduce the problem
$ echo '{ a: 1, aa: 2 }.select { |k| /aa/.match? k }' | rubocop -sx -A
Inspecting 1 file
C
Offenses:
x:1:1: C: [Corrected] Style/SelectByRegexp: Prefer grep to select with a regexp match.
{ a: 1, aa: 2 }.select { |k| /aa/.match? k }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense corrected
====================
{ a: 1, aa: 2 }.grep(/aa/)
RuboCop version
1.22.0
The text was updated successfully, but these errors were encountered:
Autocorrection by Style/SelectByRegexp is marked unsafe because, like with a bunch of other cops, RuboCop cannot know what type your hash variable is by static analysis, so it makes its best guess.
You could disable the cop for this line or use something like hash.keys.grep(/foo/).
Expected behavior
I expect this cop to only apply to Array
select
and not to Hashselect
.Actual behavior
Hash
select
is flagged if the arity is 1, even though the suggested autocorrect is wrong. i.e.hash.select {|k| /foo/.match? k }
can't be replaced withhash.grep(/foo/)
, since single-arggrep
always returns[]
with hashes.Steps to reproduce the problem
RuboCop version
1.22.0
The text was updated successfully, but these errors were encountered: