Class: RuboCop::Cop::Rails::RequireDependency
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::RequireDependency
- Extended by:
- TargetRailsVersion
- Defined in:
- lib/rubocop/cop/rails/require_dependency.rb
Overview
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.
Constant Summary collapse
- MSG =
'Do not use `require_dependency` with Zeitwerk mode.'
- RESTRICT_ON_SEND =
%i[require_dependency].freeze
Constants included from TargetRailsVersion
TargetRailsVersion::TARGET_GEM_NAME, TargetRailsVersion::USES_REQUIRES_GEM_API
Instance Method Summary collapse
Methods included from TargetRailsVersion
minimum_target_rails_version, support_target_rails_version?
Instance Method Details
#on_send(node) ⇒ Object
32 33 34 |
# File 'lib/rubocop/cop/rails/require_dependency.rb', line 32 def on_send(node) require_dependency_call?(node) { add_offense(node) } end |