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

False positive + bad autocorrect for Rails/Pluck #842

Closed
jcoyne opened this issue Oct 26, 2022 · 2 comments
Closed

False positive + bad autocorrect for Rails/Pluck #842

jcoyne opened this issue Oct 26, 2022 · 2 comments

Comments

@jcoyne
Copy link
Contributor

jcoyne commented Oct 26, 2022

I had this line of code:

      label_value = facet_config.pivot.map(&:to_sym).map { |k| item_fq[k] }

and when I ran rubocop it complained:

Inspecting 1 file
C

Offenses:

app/presenters/blacklight/facet_item_pivot_presenter.rb:27:56: C: [Corrected] Rails/Pluck: Prefer pluck(k) over map { |k| item_fq[k] }.
        label_value = facet_config.pivot.map(&:to_sym).map { |k| item_fq[k] }
                                                       ^^^^^^^^^^^^^^^^^^^^^^

and it was autocorrected to

        label_value = facet_config.pivot.map(&:to_sym).pluck(k)

This new code is broken as k is not defined.

Rubocop version 1.37.1
rubocop-rails version 2.17.1

@jcoyne jcoyne changed the title Bad autocorrect for Rails/Pluck False positive + bad autocorrect for Rails/Pluck Oct 26, 2022
@jcoyne
Copy link
Contributor Author

jcoyne commented Oct 26, 2022

Here's another example of a bad autocorrect it did:

items.map {|_facet, opts| opts[:group] }
items.pluck(:group)

Now consider that items is:

items = { a: { group: 1}}

it results in:

no implicit conversion of Symbol into Integer (TypeError)

@vlad-pisanov
Copy link
Contributor

This is same as #833 -- the fix is on master 🙌

@jcoyne jcoyne closed this as completed Oct 26, 2022
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

No branches or pull requests

2 participants