Ruby 2.7 kwargs deprecation warnings
As mentioned in https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/, Ruby 2.7 introduces the following deprecation warning:
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
Because the automatic conversion is sometimes too complex and troublesome as described in the final section. So it’s now deprecated in Ruby 2.7 and will be removed in Ruby 3. In other words, keyword arguments will be completely separated from positional one in Ruby 3. So when you want to pass keyword arguments, you should always use foo(k: expr) or foo(**expr). If you want to accept keyword arguments, in principle you should always use def foo(k: default) or def foo(k:) or def foo(**kwargs).
From !38633 (closed), we collected:
- 33,637 warnings in total (including Rails deprecation and other warnings)
- 12,689 have to do with warning: Using the last argument as keyword parameters is deprecated over 485 unique locations
https://discuss.rubyonrails.org/t/new-2-7-3-0-keyword-argument-pain-point/74980 has a lot of discussion about this deprecation.
&2380 (comment 418910925) has a list of all the warnings.
Run RUBYOPT="-W:deprecated" bin/rspec <spec-file>
to reproduce.
The following checklist lists the deprecations as of https://gitlab.com/gitlab-org/gitlab/-/jobs/994927780:
Grep for the filenames in deprecations.zip to find the specs involved:
-
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/support/helpers/next_instance_of.rb:28: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/rspec-mocks-3.10.0/lib/rspec/mocks/message_expectation.rb:101: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:890: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/devise-4.7.3/lib/devise/test/controller_helpers.rb:35: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/ee/lib/ee/gitlab/usage_data.rb:449: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/lib/gitlab/utils/usage_data_spec.rb:400: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/lib/gitlab/utils/usage_data_spec.rb:409: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/lib/gitlab/utils/usage_data_spec.rb:418: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/lib/gitlab/utils/usage_data_spec.rb:437: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/lib/gitlab/utils/usage_data_spec.rb:442: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/attr_encrypted-3.1.0/lib/attr_encrypted/adapters/active_record.rb:63: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/rspec-mocks-3.10.0/lib/rspec/mocks/message_expectation.rb:694: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/spec/support/gitlab_experiment.rb:7: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/rspec-expectations-3.10.0/lib/rspec/matchers/built_in/has.rb:67: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/grape-1.5.1/lib/grape/middleware/stack.rb:97: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/grape-1.5.1/lib/grape/validations/validators/coerce.rb:21: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/grape_logging-1.8.3/lib/grape_logging/middleware/request_logger.rb:17: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/factory_bot-6.1.0/lib/factory_bot/decorator.rb:16: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/cache.rb:330: warning: Passing the keyword argument as the last hash parameter is deprecated -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/rouge-3.26.0/lib/rouge/formatter.rb:46: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/batch-loader-1.4.0/lib/batch_loader/graphql.rb:38: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/carrierwave-1.3.1/lib/carrierwave/sanitized_file.rb:316: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/ee/lib/ee/gitlab/usage_data.rb:452: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call -
DEPRECATION WARNING: /builds/gitlab-org/gitlab/vendor/ruby/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/relation.rb:412: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call