We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Rails/Pluck
The cop should not suggest to use pluck when there are multiple block arguments or when the argument is used inside the block.
pluck
Rubocop is suggesting to use pluck, which is not the correct solution (the code would break). Likely related with #831 (/cc @koic)
Ignore the non-sense example, it's mainly to show the 2 wrong suggestions on the two map:
map
class Test def test id_values = { 10 => 'foo', 20 => 'bar', 30 => 'baz' } items = {} 50.times do |i| items[i] = { 'condition' => rand(2).zero?, 'id' => i } end true_items, _false_items = items.partition { |_, item| item['condition'] } true_items_ids = true_items.map { |_, obj| obj['id'] } true_items_ids.map { |id| id_values[id] } end end
Offenses: test.rb:12:33: C: [Correctable] Rails/Pluck: Prefer pluck('id') over map { |_, obj| obj['id'] }. true_items_ids = true_items.map { |_, obj| obj['id'] } ^^^^^^^^^^^^^^^^^^^^^^^^^^ test.rb:14:20: C: [Correctable] Rails/Pluck: Prefer pluck(id) over map { |id| id_values[id] }. true_items_ids.map { |id| id_values[id] } ^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 2 offenses detected, 2 offenses autocorrectable
1.37.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [x86_64-linux] - rubocop-rails 2.17.1
The text was updated successfully, but these errors were encountered:
85d615f
[Fix #833] Fix a false positive for Rails/Pluck
fbc59de
Fixes #833. This commit fixes a false positive for `Rails/Pluck` when receiver is not block argument for `[]`.
No branches or pull requests
Expected behavior
The cop should not suggest to use
pluck
when there are multiple block arguments or when the argument is used inside the block.Actual behavior
Rubocop is suggesting to use
pluck
, which is not the correct solution (the code would break). Likely related with #831 (/cc @koic)Steps to reproduce the problem
Ignore the non-sense example, it's mainly to show the 2 wrong suggestions on the two
map
:RuboCop version
The text was updated successfully, but these errors were encountered: