Sha256: 9b3886009f58522de87503d84021ec1190a4e822e9f0a066a63564cd8ce1c95d

Contents?: true

Size: 953 Bytes

Versions: 3

Compression:

Stored size: 953 Bytes

Contents

# frozen_string_literal: true

require_relative '../../../gitlab/styles/rubocop/model_helpers'

module Rubocop
  module Cop
    module Rails
      class IncludeUrlHelper < RuboCop::Cop::Base
        MSG = <<~MSG
          Avoid including `ActionView::Helpers::UrlHelper`.
          It adds/overrides ~40 methods while usually only one is needed.
          Instead, use the `Gitlab::Routing.url_helpers`/`Application.routes.url_helpers`(outside of gitlab)
          and `ActionController::Base.helpers.link_to`.
          See https://gitlab.com/gitlab-org/gitlab/-/issues/340567.
        MSG

        # @!method include_url_helpers_node?(node)
        def_node_matcher :include_url_helpers_node?, <<~PATTERN
          (send nil? :include (const (const (const {nil? cbase} :ActionView) :Helpers) :UrlHelper))
        PATTERN

        def on_send(node)
          add_offense(node) if include_url_helpers_node?(node)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gitlab-styles-9.2.0 lib/rubocop/cop/rails/include_url_helper.rb
gitlab-styles-9.1.0 lib/rubocop/cop/rails/include_url_helper.rb
gitlab-styles-9.0.0 lib/rubocop/cop/rails/include_url_helper.rb