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

Enhancement: Rails/Pluck to support strings / literals? #787

Closed
vlad-pisanov opened this issue Sep 21, 2022 · 0 comments · Fixed by #789
Closed

Enhancement: Rails/Pluck to support strings / literals? #787

vlad-pisanov opened this issue Sep 21, 2022 · 0 comments · Fixed by #789

Comments

@vlad-pisanov
Copy link
Contributor

Currently, Rails/Pluck only detects symbol keys, such as:

[ { a: 42 }].map { |x| x[:a] }
# cop recommends [ { a: 42 }].pluck(:a) 

but not String keys:

[ { 'a' => 42 }].map { |x| x['a'] }
# cop ignores

pluck() supports both Symbols and Strings, so it seems like this cop should work on both datatypes. It might actually work for any literal:

[ { false => 42 } ].pluck(false)
# => [42]
koic added a commit to koic/rubocop-rails that referenced this issue Sep 22, 2022
Fixes rubocop#787.

This PR makes `Rails/Pluck` aware of all keys.
@koic koic closed this as completed in #789 Oct 1, 2022
koic added a commit that referenced this issue Oct 1, 2022
[Fix #787] Make `Rails/Pluck` aware of all keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant