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 3.0] Fix Ruby 2.7's deprecation warnings #18021

Merged
merged 22 commits into from
Mar 10, 2021

Conversation

ainame
Copy link
Contributor

@ainame ainame commented Jan 21, 2021

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

As per plan #17931, I've been working on Ruby 3.0 migration in fastlane project. Prior to this PR, I have enabled CI testing for Ruby 2.7 #17861. We can now run unit testing in Ruby 2.7 in order to see if there are deprecation warnings by leveraging the new option "-W:deprecated" in Ruby 2.7.2.

Deprecation warnings are off by default on 2.7.2 and later. You can turn on deprecation warnings by specifying the -w or -W:deprecated option at the command-line.
https://www.ruby-lang.org/en/news/2020/10/02/ruby-2-7-2-released/

There is a minor breaking change in Ruby 3.0 which is called "Separation of positional and keyword arguments". In short, the below code won't run on Ruby 3.0. Previously you could pass a Hash object as keyword arguments to a method, but now you need to either use ** to turn Hash into keywords arguments or simply use keywords to pass parameters. This is the most common case we need to fix.

def say(string:)
  puts string
end
params = { string: "Hello" }

# Bad in Ruby 3.0
say(params)
say({ string: "Hello" })

# Good in Ruby 3.0
say(string: "Hello")
say(**params)
say(**{ string: "Hello" })

See details below.
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

Thanks to the warnings, I could fix them as far as I got. There might be more within this project potentially but it's impossible to review every single line of code. So I expect the community to report something not working on Ruby 3.0 if they find once the whole migration is done in future🙇

Note that this PR mostly covers the codebase within this project. There are also the same warnings from dependencies. I will work on it in another PR.

Description

Other than adding ** or giving parameters to keyword arguments, I did the followings.

  • Update Rakefile and .circleci/config.yml to prevent regressions by monitoring deprecation warnings
  • Clean up unused attributes in FastlaneCore::Project
  • Using keywords arguments in ERB.new
  • Relax dependencies' versioning in gemspec for testing libraries, which allows us to fix some warnings quickly

This is the list I used as a reference of where to fix. As I mentioned, I didn't try to fix issues in slack-notifier and rspec-mocks in this list.
https://gist.github.com/ainame/d7f1c4d2fb07f139d3a0f064d4cbda75

Testing Steps

CI passed unit tests on all the environments. I will give it a try on my project briefly, too🙂

@google-cla google-cla bot added the cla: yes label Jan 21, 2021
@ainame ainame changed the title Fix Ruby 2.7's deprecation warnings Fix most Ruby 2.7's deprecation warnings Jan 23, 2021
@ainame ainame changed the title Fix most Ruby 2.7's deprecation warnings [Ruby 3.0] Fix most Ruby 2.7's deprecation warnings Jan 23, 2021
@ainame ainame force-pushed the fix-ruby2.7-warnings branch 9 times, most recently from f9d10f2 to b210953 Compare January 26, 2021 04:53
@ainame ainame force-pushed the fix-ruby2.7-warnings branch 4 times, most recently from 4075c44 to 5e3144b Compare February 21, 2021 03:15
@ainame ainame requested a review from joshdholtz March 9, 2021 13:35
@ainame
Copy link
Contributor Author

ainame commented Mar 9, 2021

Merged the main branch into this and no new warning is there.

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

This looks good to me! LGTM 🥳

@ainame
Copy link
Contributor Author

ainame commented Mar 10, 2021

This branch has the latest change in the main branch and no new warning. It's good to merge now.

@ainame ainame merged commit d6256d6 into fastlane:master Mar 10, 2021
@ainame ainame deleted the fix-ruby2.7-warnings branch March 10, 2021 14:28
Copy link

@fastlane-bot fastlane-bot left a comment

Choose a reason for hiding this comment

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

Congratulations! 🎉 This was released as part of fastlane 2.178.0 🚀

@fastlane fastlane locked and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants