https://about.gitlab.com/blog/2021/02/03/how-we-automatically-fixed-hundreds-of-ruby-2-7-deprecation-warnings/ [slp-icon] Talk to an expert Get free trial [slp-search] [slp-user] [slp-hambur] [ ] Product [slp-caret-] * GitLab: the DevOps platform * Explore GitLab * Install GitLab * How GitLab compares --------------------------------------------------------------------- Solutions [slp-caret-] By Organization Type * Enterprise * Small business * Public sector By Use Case * Continuous integration (CI/CD) * Source code management * Out-of-the-box pipelines * Security (DevSecOps) * Software Supply Chain Security * Agile development * Value stream management * GitOps * The DevOps Platform --------------------------------------------------------------------- Resources [slp-caret-] Product Resources * Getting started * Industry topics and trends * GitLab docs * GitLab Learn * Blog * Services * Customer case studies * Additional resources People Resources * Working remotely * Community programs * Upcoming events * 2021 Developer survey results --------------------------------------------------------------------- Partners [slp-caret-] Meet Our Partners * GitLab partners Technology Partners * Find a technology partner * Become a technology partner Channel Partners * Find a channel partner * Become a channel partner --------------------------------------------------------------------- Pricing --------------------------------------------------------------------- Support [slp-caret-] * Contact Support * Support resources --------------------------------------------------------------------- Login Talk to an expert Get Free Trial [slp-logo] [slp-icon] Product GitLab: the DevOps platform - Discover all-in-one software delivery. Explore GitLab - See repositories in action with GitLab projects. Install GitLab - Install one package, run a complete solution. How GitLab compares - See why we're the best in DevOps Solutions By Organization Type Enterprise - Adopt one platform for endless possibilities. Small business - Get a DevOps platform that grows with you. Public sector - Trusted by government. Loved by developers. By Use Case Continuous integration (CI/CD) - Automate everything, accelerate deployment. Source code management - Build the future with a shared history. Out-of-the-box pipelines - Adopt DevOps with a single commit. Security (DevSecOps) - Integrate security, deliver faster continuously. Software Supply Chain Security - Ensure your software supply chain is secure and compliant. Agile development - Keep your methodology, gain functionality. Value stream management - Visualize what works and optimize the rest. GitOps - Simplify IT with DevOps-style automation. The DevOps Platform - Develop secure software faster in a single platform. Resources Product Resources Getting started - Explore our quick-start checklist. Industry topics and trends - Get cross-functional software delivery insights. GitLab docs - Access step-by-step tutorials and guides. GitLab Learn - Explore GitLab learning resources. Blog - Read up on releases, contributions, and more. Services - Adopt DevOps faster with our support services. Customer case studies - Learn why top companies trust GitLab for DevOps. Additional resources - Download knowledge, expand to production. People Resources Working remotely - Discover how we work better together - wherever. Community programs - Access contributor resources and startup grants. Upcoming events - Find meetups, webinars, conferences, and more. 2021 Developer survey results - See DevSecOps through the eyes of practitioners Partners Meet Our Partners GitLab partners - Check out our technology and channel partners. Technology Partners Find a technology partner - See our cloud partners and other integrators. Become a technology partner - Join our DevOps partner ecosystem. Channel Partners Find a channel partner - Find resellers, solution providers, and more. Become a channel partner - Grow your business alongside our DevOps experts. Pricing Support Contact Support - Find out how, where, and when we offer support. Support resources - Explore support documents and instructions. Talk to an expert Get free trial [slp-search] [slp-user] [ ] Blog / Engineering open source How we automatically fixed thousands of Ruby 2.7 deprecation warnings Thong Kuah * Feb 3, 2021 * 3 min read * Leave a comment Thong Kuah GitLab profile --------------------------------------------------------------------- [daria-nepriakhina-zNU3ErDAbAw-unsplash] Ruby 3.0 was just released on Dec. 25, 2020, with some new features and some breaking changes. GitLab was at Ruby 2.6, and we wanted to upgrade to Ruby 2.7 in preparation to eventually upgrade to Ruby 3. In Ruby 3.0, positional and keyword arguments will be separated. To help developers prepare for this, in Ruby 2.7, warnings were added. In GitLab, we discovered we have thousands of such warnings across hundreds of files: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call Boring solutions To address this warning, the obvious, and boring solution was to simply add ** to the last keyword argument. For the most part, this is what we did. However, while this was under way, we also developed a RuboCop check that could detect, and automatically fix the keyword arguments. The benefit for this approach was that we can autocorrect any existing warnings en masse. The tricky part about this is that RuboCop is designed to statically analyze Ruby code, whereas the warnings were generated by Ruby at runtime. A way forward After some research, we found a way to utilize our comprehensive RSpec test suite to gather all the warnings using the Deprecation Toolkit gem. We also considered using the warning gem at one point, but preferred Deprecation Toolkit as the results were easier to process. Deprecation Toolkit supports RSpec out of the box, so it was really simple to configure. It also has a simple YAML-based file format to record all deprecations. We then adapted this to record deprecation warnings for Ruby 2.7 last keyword arguments with: kwargs_warnings = [ # Taken from https://github.com/jeremyevans/ruby-warning/blob/1.1.0/lib/warning.rb#L18 %r{warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z} ] DeprecationToolkit::Configuration.warnings_treated_as_deprecation = kwargs_warnings Lastly, we wrote a new RuboCop check, called Lint/LastKeywordArgument , that checks against the YAML files generated by Deprecation Toolkit, and generates offenses. Now we can very quickly, statically check the whole GitLab codebase, and even autocorrect! You can see how Deprecation Toolkit and the LastKeywordArgument check was put together in this merge request. You can see a sample output from running the LastKeywordArgument cop check: LastKeywordArgument RuboCop offenses Sample output from running the LastKeywordArgument cop check Automatically fix everything Now we have an automatic RuboCop check, which can also autocorrect, we create merge requests to autocorrect! For example, we autocorrected 62 instances across 39 spec files. Automation for the win! We then went one step further, and integrated this in our GitLab CI pipelines. Using the artifacts feature of GitLab CI, we gathered the deprecations directory from all RSpec jobs (we have about 400 such jobs). After all the RSpec jobs have passed, we then made a post-test job to check the results with the LastKeywordArgument cop. Below is a snippet of the GitLab CI .gitlab-ci.yml configuration: stages: - test - post-test # This inherited job is used by all RSpec jobs .rspec-base: stage: test artifacts: - deprecations/ # GitLab CI job artifacts from previous stages are passed to this job rspec:deprecations: stage: post-test script: - bundle exec rubocop --only Lint/LastKeywordArgument --parallel artifacts: - deprecations/ This enabled us to have a single job where we can see all deprecation warnings. Conclusion With this measure we went from about 30,000 warnings related to keyword arguments to about 800 remaining warnings, largely stemming from dependencies. Feel free to follow our progress in GitLab issue # 257438, and contribute to fix the remaining warnings if you are interested! Cover image by Daria Nepriakhina on Unsplash Free eBook: The benefits of single application CI/CD Download the ebook to learn how you can utilize CI/CD without the costly integrations or plug-in maintenance. Learn more [benefits-o] Sign up for GitLab's twice-monthly newsletter Thanks for subscribing! --------------------------------------------------------------------- Tags: open source More to explore engineering We need to talk: Can we standardize NO_PROXY? Stan Hu GitLab profile Stan Hu engineering Meet Praefect: The traffic manager making your Git data highly available engineering How we used parallel CI/CD jobs to increase our productivity Miguel Rincon GitLab profile Miguel Rincon All Blog Posts * Twitter * Facebook * YouTube * LinkedIn Why GitLab? * Product * Solutions * Services * DevOps tools * Is it any good? * Releases * Pricing * Get started Resources * All resources * All-Remote * Blog * Newsletter * Events * Webcasts * Topics * Training * Docs * Developer Portal * Install Community * Customers * Contribute * Community Programs * Direction * Technology Partners * Channel Partners * Open Source Partners * GitLab for Open Source * GitLab for Education * GitLab for Startups * Shop * Community Forum Support * Get help * Contact Sales * Contact Support * Support options * Status * Customers Portal Company * About * What is GitLab? * Jobs * Culture * Leadership * Team * Press * Investor Relations * Analysts * Handbook * Security * Contact * Terms * Privacy * * Trademark Git is a trademark of Software Freedom Conservancy and our use of 'GitLab' is under license View page source -- Edit in Web IDE -- please contribute. (c) GitLab B.V.