Skip to content

RuboCop: Enable Style/ArgumentsForwarding

What does this MR do and why?

This MR enables Style/ArgumentsForwarding with the non-default configuration of AllowOnlyRestArgument: false.

This means it only flags code if args and &block are passed as-is to another method and suggests to use .... If &block is omitted it is still flagged. See !110225 (comment 1253998448).

# bad
def foo(*args, &block)
  bar(*args, &block)
end

# bad
def foo(*args, **kwargs, &block)
  bar(*args, **kwargs, &block)
end

# bad
def foo(*args)
  bar(*args)
end

# bad
def foo(**kwargs)
  bar(**kwargs)
end

# good
def foo(...)
  bar(...)
end

See #389418 (comment 1253729431)

Note this cop rule will be backported to gitlab-styles at some point. See gitlab-org/ruby/gems/gitlab-styles#43 (comment 1253905098)

Offenses

29706 files inspected, 14 offenses detected, 14 offenses autocorrectable

Click to expand

Offenses:

app/finders/clusters/knative_services_finder.rb:24:38: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
    def with_reactive_cache_memoized(*cache_args, &block)
                                     ^^^^^^^^^^^^^^^^^^^
app/finders/clusters/knative_services_finder.rb:26:29: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
        with_reactive_cache(*cache_args, &block)
                            ^^^^^^^^^^^^^^^^^^^
app/presenters/gitlab/blame_presenter.rb:82:17: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
    def link_to(*args, &block)
                ^^^^^^^^^^^^^
app/presenters/gitlab/blame_presenter.rb:83:46: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
      ActionController::Base.helpers.link_to(*args, &block)
                                             ^^^^^^^^^^^^^
app/presenters/gitlab/blame_presenter.rb:86:17: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
    def mail_to(*args, &block)
                ^^^^^^^^^^^^^
app/presenters/gitlab/blame_presenter.rb:87:46: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
      ActionController::Base.helpers.mail_to(*args, &block)
                                             ^^^^^^^^^^^^^
ee/lib/gitlab/elastic/expr_name.rb:18:16: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
      def name(*context, &block)
               ^^^^^^^^^^^^^^^^
ee/lib/gitlab/elastic/expr_name.rb:19:23: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
        @context.name(*context, &block)
                      ^^^^^^^^^^^^^^^^
qa/qa/scenario/actable.rb:6:15: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
      def act(*args, &block)
              ^^^^^^^^^^^^^
qa/qa/scenario/actable.rb:7:23: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
        instance_exec(*args, &block)
                      ^^^^^^^^^^^^^
qa/qa/scenario/actable.rb:19:17: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
        def act(*args, &block)
                ^^^^^^^^^^^^^
qa/qa/scenario/actable.rb:20:19: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
          new.act(*args, &block)
                  ^^^^^^^^^^^^^
spec/lib/gitlab/pagination/offset_pagination_spec.rb:307:21: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
  def expect_header(*args, &block)
                    ^^^^^^^^^^^^^
spec/lib/gitlab/pagination/offset_pagination_spec.rb:308:46: C: [Correctable] Style/ArgumentsForwarding: Use arguments forwarding.
    expect(subject).to receive(:header).with(*args, &block)
                                             ^^^^^^^^^^^^^

29706 files inspected, 14 offenses detected, 14 offenses autocorrectable

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