Skip to content

Instantly share code, notes, and snippets.

@SpComb
Last active May 15, 2018 14:34
Show Gist options
  • Select an option

  • Save SpComb/483b2e36ce80c52aa48f9e76cfe4f612 to your computer and use it in GitHub Desktop.

Select an option

Save SpComb/483b2e36ce80c52aa48f9e76cfe4f612 to your computer and use it in GitHub Desktop.
ruby 2.6 warnings vs rubocop linter checks re ruby 3 keyword argument changes
def foo(arg, options = {})
puts "foo(#{arg.inspect}, #{options.inspect})"
end
def bar(arg, **options)
puts "bar(#{arg.inspect}, **#{options.inspect})"
end
def asdf(arg, test: nil)
puts "asdf(#{arg.inspect}, test: #{test.inspect})"
end
options = { test: true }
foo('a', options) # valid
foo('a', **options) # ruby 2.6 warning, rubocop warning, invalid for ruby3?
foo('a', test: true) # invalid for ruby3?
foo('a', **options, test: false) # ruby 2.6 warning, rubocop warning, invalid for ruby3?
bar('b', options) # invalid for ruby3?
bar('b', **options) # valid, rubocop warning
bar('b', test: true) # valid
bar('b', **options, test: false) # valid, rubocop warning
asdf('c', options) # invalid for ruby3?
asdf('c', **options) # valid, rubocop warning
asdf('c', test: true) # valid
asdf('c', **options, test: false) # valid, rubocop warning
Inspecting 1 file
W
Offenses:
test/asdf.rb:1:1: C: Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
def foo(arg, options = {})
^
test/asdf.rb:16:10: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
foo('a', **options)
^^^^^^^^^
test/asdf.rb:18:10: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
foo('a', **options, test: false)
^^^^^^^^^
test/asdf.rb:21:10: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
bar('b', **options)
^^^^^^^^^
test/asdf.rb:23:10: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
bar('b', **options, test: false)
^^^^^^^^^
test/asdf.rb:26:11: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
asdf('c', **options)
^^^^^^^^^
test/asdf.rb:28:11: W: Lint/SplatKeywordArguments: Do not use splat keyword arguments as a single Hash.
asdf('c', **options, test: false)
^^^^^^^^^
1 file inspected, 7 offenses detected
foo("a", {:test=>true})
/test/asdf.rb:16: warning: passing splat keyword arguments as a single Hash to `foo'
foo("a", {:test=>true})
foo("a", {:test=>true})
/test/asdf.rb:18: warning: passing splat keyword arguments as a single Hash to `foo'
foo("a", {:test=>false})
bar("b", **{:test=>true})
bar("b", **{:test=>true})
bar("b", **{:test=>true})
bar("b", **{:test=>false})
asdf("c", test: true)
asdf("c", test: true)
asdf("c", test: true)
asdf("c", test: false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment