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

Autocorrection support on Performance/MapMethodChain #436

Closed
r7kamura opened this issue Jan 27, 2024 · 2 comments
Closed

Autocorrection support on Performance/MapMethodChain #436

r7kamura opened this issue Jan 27, 2024 · 2 comments

Comments

@r7kamura
Copy link
Contributor

r7kamura commented Jan 27, 2024

Is your feature request related to a problem? Please describe.

While using rubocop-performance, I encountered the following offense:

example.rb:111:43: C: Performance/MapMethodChain: Use map { |x| x.value.to_s } instead of map method chain.
  items.map(&:value).map(&:to_s)
        ^^^^^^^^^^^^^^^^^^^^^^^^

I see. So you want me to use map { |x| x.value.to_s } instead. If you go so far as to say that, wouldn't it be nice if you supported autocorrect?

The comment states that autocorrection is not supported because appropriate block argument names cannot be determined.

# Autocorrection is not supported because an appropriate block variable name cannot be determined automatically.

Since the message says to use x, shouldn't it be x?

Or, you say that the good example code uses item, why not just use item?

# # bad
# array.map(&:foo).map(&:bar)
#
# # good
# array.map { |item| item.foo.bar }

I believe that it is more valuable to provide autocorrection than to provide perfectly considered argument names.

Describe the solution you'd like

How about supporting the autocorrection feature with an argument name of item?

Describe alternatives you've considered

Alternatively, using numbered parameters _1 or, in future Ruby, it could be an option.

Additional context

Performance/MapMethodChain cop was added at the following pull request:

I searched past Issues, comments, etc., but could not find any indication that this point has already been discussed.

@koic
Copy link
Member

koic commented Jan 27, 2024

Autocorrect is complementary and should not be named arbitrarily. Also, it can be assumed that people's tastes (and situations) will likely differ, so there will still be some skepticism as to whether it can be replaced.

@koic koic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2024
@r7kamura
Copy link
Contributor Author

I understand that autocorrection will not be supported in the future. Thank you for your quick response 👍

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