Class: RuboCop::Cop::Lint::DeprecatedReference
- Includes:
- ProjectIndexHelp
- Defined in:
- lib/rubocop/cop/lint/deprecated_reference.rb
Overview
Checks for calls to methods and references to constants that are documented
as deprecated with a YARD @deprecated tag.
The check is powered by the project-wide index, so it only runs when
AllCops/UseProjectIndex is enabled and the rubydex gem is installed.
Without the index the cop does nothing.
Only references that can be resolved without type inference are checked:
constants, method calls without an explicit receiver (or with self),
which are looked up in the enclosing class or module and its ancestry,
and calls whose receiver is a constant, which are looked up in that
namespace's singleton class. Calls on arbitrary objects are not checked.
References made from a definition that is itself deprecated are allowed, so deprecated implementations can keep calling each other.
Constant Summary collapse
- METHOD_MSG =
'Method `%<name>s` is deprecated%<detail>s'- CONSTANT_MSG =
'Constant `%<name>s` is deprecated%<detail>s'- DEPRECATED_TAG =
'@deprecated'- DEPRECATION_DETAIL =
/#{DEPRECATED_TAG}\s+(.+)/.freeze
Constants included from ProjectIndexHelp
ProjectIndexHelp::BUILTIN_DOCUMENT_URI, ProjectIndexHelp::FILE_URI_PREFIX, ProjectIndexHelp::WINDOWS_DRIVE_PREFIX
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#config, #processed_source, #project_index
Instance Method Summary collapse
- #on_const(node) ⇒ Object
- #on_new_investigation ⇒ Object
- #on_send(node) ⇒ Object (also: #on_csend)
Methods included from ProjectIndexHelp
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #parser_engine, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_gem_version, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
cop_dir_for, #exclude_limit, read_limits
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#on_const(node) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rubocop/cop/lint/deprecated_reference.rb', line 82 def on_const(node) return unless project_index return if node.parent&.defined_module declaration = resolve_constant_in_index(node) return unless declaration && deprecated?(declaration) return if within_deprecated_definition?(node) = format(CONSTANT_MSG, name: node.const_name, detail: detail_for(declaration)) add_offense(node, message: ) end |
#on_new_investigation ⇒ Object
65 66 67 68 |
# File 'lib/rubocop/cop/lint/deprecated_reference.rb', line 65 def on_new_investigation @namespace_cache = {} super end |
#on_send(node) ⇒ Object Also known as: on_csend
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubocop/cop/lint/deprecated_reference.rb', line 70 def on_send(node) return unless project_index declaration = method_declaration_for(node) return unless declaration && deprecated?(declaration) return if within_deprecated_definition?(node) = format(METHOD_MSG, name: node.method_name, detail: detail_for(declaration)) add_offense(node.loc.selector, message: ) end |