pharos-cluster icon indicating copy to clipboard operation
pharos-cluster copied to clipboard

Fix usages of double-splat with keyword arguments before Ruby 2.6

Open kke opened this issue 7 years ago • 3 comments

Cop disabled in #364

Ruby 2.6 will give a deprecation warning if you use them together like:

def foo(bar: nil, **options)

as described here: https://bugs.ruby-lang.org/issues/14183

kke avatar May 15 '18 10:05 kke

Ruby 2.6 will give a deprecation warning if you use them together like:

I don't think that's what the issue says... my reading is that will continue to work fine, what's being deprecated is treating keyword arguments as a final positional hash:

def foo(a, options)
    ...
end
def bar(b, foo: nil)
    ...
end
foo('a', bar: false) # this will break
bar('b', options) # this will break

SpComb avatar May 15 '18 11:05 SpComb

Testing to show that rubocop is giving false positives: https://gist.github.com/SpComb/483b2e36ce80c52aa48f9e76cfe4f612

Based on my understanding of the upcoming ruby3 changes, only 3/4 of the foo(...) usages should be giving warnings in ruby 2.6, but the foo('a', test: true) case isn't. AFAIK all of the bar and asdf usages are fine?

SpComb avatar May 15 '18 11:05 SpComb

So if we have any usages like foo that call methods defined to take positional arguments with keyword arguments, then yes, those should be fixed to use real keyword arguments... however, I think there's going to be approximately one million of those kinds of usages throughout our dependency gems, so I wouldn't worry too much about the ones in our own codebase...?

The ruby 2.6 warnings seem to be specific to the foo('a', **options) usage, but the ruby 3 changes seem to also cover usages like foo('a', test: true), which are far more common.

SpComb avatar May 15 '18 11:05 SpComb