Sha256: 26c4dccdabce95f3ebc93ffd28ccb0f3e91f3c6f552038936fa7a820ceda8b9e

Contents?: true

Size: 1.23 KB

Versions: 13

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # Checks for the usage of `require_dependency`.
      #
      # `require_dependency` is an obsolete method for Rails applications running in Zeitwerk mode.
      # In Zeitwerk mode, the semantics should match Ruby's and no need to be defensive with load order,
      # just refer to classes and modules normally.
      # If the constant name is dynamic, camelize if needed, and constantize.
      #
      # Applications running in Zeitwerk mode should not use `require_dependency`.
      #
      # NOTE: This cop is disabled by default. Please enable it if you are using Zeitwerk mode.
      #
      # @example
      #   # bad
      #   require_dependency 'some_lib'
      class RequireDependency < Base
        extend TargetRailsVersion

        minimum_target_rails_version 6.0

        MSG = 'Do not use `require_dependency` with Zeitwerk mode.'
        RESTRICT_ON_SEND = %i[require_dependency].freeze

        def_node_matcher :require_dependency_call?, <<~PATTERN
          (send {nil? (const _ :Kernel)} :require_dependency _)
        PATTERN

        def on_send(node)
          require_dependency_call?(node) { add_offense(node) }
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/require_dependency.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/require_dependency.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/require_dependency.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/require_dependency.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.17.2 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.17.1 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.17.0 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.16.1 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.16.0 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.15.2 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.15.1 lib/rubocop/cop/rails/require_dependency.rb
rubocop-rails-2.15.0 lib/rubocop/cop/rails/require_dependency.rb