Module: RuboCop::Cop::ProjectIndexHelp
- Included in:
- Lint::ConstantReassignment, Lint::ConstantResolution, Lint::DeprecatedReference, Lint::DuplicateMethods, Lint::InheritException, Lint::MissingSuper, Lint::NameTypo, Lint::UnusedPrivateMethod, Naming::AccessorMethodName, Naming::PredicatePrefix, Style::ClassAndModuleChildren, Style::Documentation, Style::MissingRespondToMissing, Style::RedundantConstantBase, Style::StaticClass
- Defined in:
- lib/rubocop/cop/mixin/project_index_help.rb
Overview
Common helpers for cops that consult the project-wide static-analysis index
via Cop::Base#project_index.
Mixed-in cops gain the external_dependency_checksum override that invalidates
the ResultCache whenever the indexed project files change on disk.
To run index-backed analysis, cops should simply check whether project_index is non-nil;
the runner only exposes a non-nil index when the user opted in via AllCops/UseProjectIndex
and the underlying gem is available.
Constant Summary collapse
- BUILTIN_DOCUMENT_URI =
'rubydex:built-in'- FILE_URI_PREFIX =
'file://'- WINDOWS_DRIVE_PREFIX =
Matches the spurious leading slash before a Windows drive letter that remains after stripping
file://from afile:///C:/...URI. %r{\A/(?=[A-Za-z]:[/\\])}.freeze
Class Attribute Summary collapse
-
.cached_index_signature ⇒ Object
The signature is a property of the index, not of the cop, and computing it stats every indexed file, so all cops sharing an index share one computation.
Instance Method Summary collapse
Class Attribute Details
.cached_index_signature ⇒ Object
The signature is a property of the index, not of the cop, and computing it stats every indexed file, so all cops sharing an index share one computation. A single-entry cache (instead of a hash keyed by index) avoids retaining stale graphs in long-lived processes.
25 26 27 |
# File 'lib/rubocop/cop/mixin/project_index_help.rb', line 25 def cached_index_signature @cached_index_signature end |
Instance Method Details
#external_dependency_checksum ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/rubocop/cop/mixin/project_index_help.rb', line 28 def external_dependency_checksum return nil unless project_index @external_dependency_checksum ||= Digest::SHA1.hexdigest( project_index_signature.join("\n") ) end |