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

Ruby 2.6 warning: passing splat keyword arguments as a single Hash #32612

Merged
merged 1 commit into from Apr 17, 2018

Conversation

utilum
Copy link
Contributor

@utilum utilum commented Apr 17, 2018

Before:

$ ruby -v
ruby 2.6.0dev (2018-04-04 trunk 63085) [x86_64-linux]

$ bundle exec rake test:template
...
/rails/actionview/lib/action_view/digestor.rb:76: warning: passing splat keyword arguments as a single Hash to `find_all'

See:
https://travis-ci.org/rails/rails/jobs/367493803#L1516-L1874

Before:

```
$ ruby -v
ruby 2.6.0dev (2018-04-04 trunk 63085) [x86_64-linux]

$ bundle exec rake test:template
...
/rails/actionview/lib/action_view/digestor.rb:76: warning: passing splat keyword arguments as a single Hash to `find_all'
```
@rails-bot
Copy link

r? @rafaelfranca

(@rails-bot has picked a reviewer for you, use r? to override)

@rafaelfranca
Copy link
Member

Can you fix all the remaining places where this warning is being raised in the same PR. This is the 3rd PR for the same change.

@utilum
Copy link
Contributor Author

utilum commented Apr 17, 2018

In current master this is the last place. I wanted to add this to the 2nd PR when it popped up, but took longer to figure out the proper way. Sorry.
That said, we also need to to watch out not to create new calls that raise this warning.
This fixes a commit from four days ago, 4f99a21#diff-7ee9dc74b44ac1e2c604f7bc0791475dR76, after the 2nd PR was submitted.
And 84b1fee#diff-90026976e5983729d8dcd51a360cf4aeR439, fixed in the 2nd PR was merged a week after the 1st PR on the same problem.

@rafaelfranca
Copy link
Member

Thanks for looking on all the other places. Yeah, not sure how to avoid introducing this warning again since it only happen on Ruby 2.6 and that version is not even released yet. Maybe we can add a rubocop rule?

@rafaelfranca rafaelfranca merged commit b05fc6e into rails:master Apr 17, 2018
@utilum utilum deleted the splat_actionview branch April 18, 2018 04:37
prefixes = args[1] || []
partial = args[2] || false
keys = args[3] || []
options = args[4] || {}
Copy link
Contributor

@printercu printercu Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just def find_template(finder, name, prefixes = [], partial = false, keys = [], options = {})?

@rafaelfranca will you accept PR with this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even find_template(finder, *args, **options) should be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Please open a PR

printercu added a commit to printercu/rails that referenced this pull request May 3, 2018
koic added a commit to koic/rubocop that referenced this pull request May 10, 2018
## Summary

This cop emulates the following Ruby warnings in Ruby 2.6.
ruby/ruby@a23eca2

```console
% ruby -we "def m(a) end; h = {foo: 1}; m(**h)"
-e:1: warning: passing splat keyword arguments as a single Hash to `m'
```

This cop does not have autocorrect because uses of splat keyword
arguments duplicates the argument hash instance.
So, it is not necessarily compatible code.

### Use splat keyword arguments (`foo(**h)`)

```console
% ruby -vwe "def m(a) p a.object_id; end; h = {k: :v}; p h.object_id; m(**h)"
ruby 2.6.0dev (2018-05-08 trunk 63359) [x86_64-darwin17]
70248917856620
-e:1: warning: passing splat keyword arguments as a single Hash to `m'
70248917856460
```

### Use non-splat keyword arguments (`foo(h)`)

```console
% ruby -vwe "def m(a) p a.object_id; end; h = {k: :v}; p h.object_id; m(h)"
ruby 2.6.0dev (2018-05-08 trunk 63359) [x86_64-darwin17]
70211441327220
70211441327220
```

## Other Information

While this warning is experimental, however work on rails/rails has begun.

- rails/rails#32447
- rails/rails#32556
- rails/rails#32612
bbatsov pushed a commit to rubocop/rubocop that referenced this pull request May 14, 2018
## Summary

This cop emulates the following Ruby warnings in Ruby 2.6.
ruby/ruby@a23eca2

```console
% ruby -we "def m(a) end; h = {foo: 1}; m(**h)"
-e:1: warning: passing splat keyword arguments as a single Hash to `m'
```

This cop does not have autocorrect because uses of splat keyword
arguments duplicates the argument hash instance.
So, it is not necessarily compatible code.

### Use splat keyword arguments (`foo(**h)`)

```console
% ruby -vwe "def m(a) p a.object_id; end; h = {k: :v}; p h.object_id; m(**h)"
ruby 2.6.0dev (2018-05-08 trunk 63359) [x86_64-darwin17]
70248917856620
-e:1: warning: passing splat keyword arguments as a single Hash to `m'
70248917856460
```

### Use non-splat keyword arguments (`foo(h)`)

```console
% ruby -vwe "def m(a) p a.object_id; end; h = {k: :v}; p h.object_id; m(h)"
ruby 2.6.0dev (2018-05-08 trunk 63359) [x86_64-darwin17]
70211441327220
70211441327220
```

## Other Information

While this warning is experimental, however work on rails/rails has begun.

- rails/rails#32447
- rails/rails#32556
- rails/rails#32612
yahonda pushed a commit to yahonda/rails that referenced this pull request Dec 24, 2018
Ruby 2.6 warning: passing splat keyword arguments as a single Hash
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

Successfully merging this pull request may close these issues.

None yet

4 participants