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

Autocorrect on inject -> each_with_object doesn't remove accumulator return #3736

Closed
nowakov opened this issue Nov 23, 2016 · 0 comments
Closed

Comments

@nowakov
Copy link

nowakov commented Nov 23, 2016

Expected behavior

[].inject({}){ |h, i| h } should be corrected to [].each_with_object({}){ |i, h| }

Actual behavior

[].inject({}){ |h, i| h } is corrected to [].each_with_object({}){ |i, h| h }

RuboCop version

$ rubocop -V
0.45.0 (using Parser 2.3.1.4, running on ruby 2.1.4 x86_64-darwin16.0)

Is that desired behaviour?

pocke added a commit to pocke/rubocop that referenced this issue Jan 15, 2017
…Style/EachWithObject`

Fix rubocop#3736

`each_with_object` doesn't use block return value.
So, the return value can be removed.

```ruby
[1, 2, 3].inject({}) do |h, i|
  h[i] = 1

  # It can't be removed.
  h
end

[1, 2, 3].each_with_object({}) do |i, h|
  h[i] = 1

  # It can be removed.
  h
end

 # Good code
[1, 2, 3].each_with_object({}) do |i, h|
  h[i] = 1
end
```
bbatsov pushed a commit that referenced this issue Jan 15, 2017
…achWithObject`

Fix #3736

`each_with_object` doesn't use block return value.
So, the return value can be removed.

```ruby
[1, 2, 3].inject({}) do |h, i|
  h[i] = 1

  # It can't be removed.
  h
end

[1, 2, 3].each_with_object({}) do |i, h|
  h[i] = 1

  # It can be removed.
  h
end

 # Good code
[1, 2, 3].each_with_object({}) do |i, h|
  h[i] = 1
end
```
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

1 participant