Skip to content

Danger: Fix warning about forwarding private methods

Peter Leitzen requested to merge pl-danger-forwardable-warning into master

What does this MR do and why?

Previously, we were using forwardable but it emitted a mysterious warning:

/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper
/builds/gitlab-org/gitlab/tooling/danger/suggestor.rb:35: warning: Tooling::Danger::Suggestion#helper at /builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/forwardable-1.3.3/lib/forwardable.rb:159 forwarding to private method Danger::Rubocop#helper

The reason is unknown because helper is a public method.

As a workaround we are switching to hand-made delegates.

Screenshots or screen recordings

Before After
https://gitlab.com/gitlab-org/gitlab/-/jobs/5407039206#L155 https://gitlab.com/gitlab-org/gitlab/-/jobs/5407172718#L159

How to set up and validate locally

  1. Apply this diff and commit
diff --git a/app/models/project.rb b/app/models/project.rb
index f7e994d4beb5..49eb90399923 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -56,7 +56,7 @@ class Project < ApplicationRecord
   extend Gitlab::ConfigHelper

   BoardLimitExceeded = Class.new(StandardError)
-  ExportLimitExceeded = Class.new(StandardError)
+  ExportLimitExceeded = Class.new(StandardError) # rubocop:disable Foo/Var

   STATISTICS_ATTRIBUTE = 'repositories_count'
   UNKNOWN_IMPORT_URL = 'http://unknown.git'
  1. On this MR, run bundle exec danger dry_run
  2. No warnings
  3. On master, run bundle exec danger dry_run
  4. See warnings

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