Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pluck: false positive? #860

Closed
akimd opened this issue Nov 8, 2022 · 0 comments · Fixed by #963
Closed

pluck: false positive? #860

akimd opened this issue Nov 8, 2022 · 0 comments · Fixed by #963
Labels
bug Something isn't working

Comments

@akimd
Copy link

akimd commented Nov 8, 2022

String#[] accepts regexes. And when used in a call to map, this cop suggests to move to using pluck. This is not wrong, it does work, but I'm not sure you actually meant to promote the use of pluck over map in this case.


Expected behavior

Don't suggest pluck in this case (?).

Actual behavior

Suggests pluck.

Steps to reproduce the problem

$ echo '%w[abc abcd bcd cd].map{|s| s[/[ab]*/]}' >/tmp/foo.rb
$ bundle exec rubocop --version
1.37.1
$ bundle exec rubocop --only Rails/Pluck /tmp/foo.rb 
Inspecting 1 file
C

Offenses:

/tmp/foo.rb:1:21: C: [Correctable] Rails/Pluck: Prefer pluck(/[ab]*/) over map{|s| s[/[ab]*/]}.
%w[abc abcd bcd cd].map{|s| s[/[ab]*/]}
                    ^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable
@koic koic added the bug Something isn't working label Mar 29, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Mar 29, 2023
Fixes rubocop#860.

This PR fixes a false positive for `Rails/Pluck`
when using regexp literal key for `String#[]`.
@koic koic closed this as completed in #963 Mar 30, 2023
koic added a commit that referenced this issue Mar 30, 2023
[Fix #860] Fix a false positive for `Rails/Pluck`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants