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

Feature request: uninformative block variable #4455

Closed
ipepe opened this issue Jun 2, 2017 · 1 comment
Closed

Feature request: uninformative block variable #4455

ipepe opened this issue Jun 2, 2017 · 1 comment

Comments

@ipepe
Copy link

ipepe commented Jun 2, 2017

Please apply

# rubocop:disable Style/SymbolProc

For examples below

I noticed that juniors tend to write code like this:

User.all.map { |x| x.name }

I would love some checking of block variable name. I know it's kind of hard because of suggesting u or user as variable name for first example and suggesting c or comments for second example:

Post.first.comments.map { |x| x.body }

It could be detected by checking the method name of enumerated chain. If it's plural, it good and it's like comments example.

But it makes examples like this impossible to work with (so much cringe):

flower = User.all
flower.map { |x| x.name }

But I would expect the cop to suggest f or flower as block variable name

Also taking all first letters from snake_case as suggestion:
product_type_versions => ptv or product_type_version

EDIT:

It could probably be described better, like: block variable name should be related to context

@Drenmi
Copy link
Collaborator

Drenmi commented Jul 2, 2017

Looks like a duplicate of #3666. Please follow that issue for updates. 🙂

I would expect the cop to suggest f or flower as block variable name

Unfortunately making the cop smart enough to suggest names is not possible. This is beacause methods can be chained, and we can't know which method refers to the thing being referenced in the block. It would likely also require us to depend on some inflection library.

@Drenmi Drenmi closed this as completed Jul 2, 2017
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