Skip to content

RuboCop: Disable cops related to Ruby 3

Peter Leitzen requested to merge pl-rubocop-disable-ruby3-cops into master

What does this MR do and why?

This MR is a follow-up of !98112 (merged) disables cops related to Ruby 3.0.

These cops emit offenses in Ruby 3.0 like https://gitlab.com/gitlab-org/gitlab/-/jobs/3067270864. Creating TODOs would conflict with Ruby 2.7. For time being we disable them only when run in Ruby 3.

Migration plan:

  • Generate TODOs for these cops (with Ruby 3.0) right before the switch to Ruby 3.0
  • Put these cops back in "grace period" to ensure master stability
  • Remove "grace period" after the switch
  • Incrementally fix TODOs

Screenshots or screen recordings

Configuration diff for Style/MutableConstant and Style/RedundantFreeze via rubocop --show-cops Style/MutableConstant,Style/RedundantFreeze with Ruby 2.7 and 3.0:

--- cops.27.txt 2022-09-22 15:37:29.340754087 +0200
+++ cops.30.txt 2022-09-22 15:37:15.516967785 +0200
@@ -1,7 +1,7 @@
 # Supports --autocorrect
 Style/MutableConstant:
   Description: Do not assign mutable objects to constants.
-  Enabled: true
+  Enabled: false
   VersionAdded: '0.34'
   VersionChanged: '1.8'
   SafeAutoCorrect: false
@@ -22,7 +22,7 @@
 # Supports --autocorrect
 Style/RedundantFreeze:
   Description: Checks usages of Object#freeze on immutable objects.
-  Enabled: true
+  Enabled: false
   VersionAdded: '0.34'
   VersionChanged: '0.66'

How to set up and validate locally

asdf local ruby 2.7.5
unset REVEAL_RUBOCOP_TODO
bundle exec rubocop --parallel --only Style/MutableConstant,Style/RedundantFreeze

asdf local ruby 3.0.4
unset REVEAL_RUBOCOP_TODO
bundle exec rubocop --parallel

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports