Module: RuboCop::Cop::RSpec::UnusedLet::References
- Included in:
- ScopeBuilder, SharedExampleRegistry
- Defined in:
- lib/rubocop/cop/rspec/unused_let/references.rb,
sig/rubocop/cop/rspec/unused_let/references.rbs
Overview
The let-visible names a single send node references. Shared by
ScopeBuilder and SharedExampleRegistry so both read references the
same way.
Constant Summary collapse
- DYNAMIC_DISPATCH_METHODS =
%i[ send public_send __send__ method respond_to? ].freeze
- SUBJECT_ALIASES =
Calls that reach the group's
subjectwithout naming it: RSpec's one-liner syntax (is_expected,should,should_not, and rspec-collection_matchers' pluralare_expected) and rspec-its (its(:size) { ... }, which derives from the subject). Normalizing them here is what lets asubjectbe resolved by the same machinery as alet, in a shared block as much as in a group. %i[is_expected are_expected should should_not its].freeze
Class Method Summary collapse
-
.references_in(node) ⇒ Object
A bare (nil receiver) call names a
let; a dynamic-dispatch call such assend(:foo)names its literal first argument.
Instance Method Summary collapse
-
#self?.references_in ⇒ Array[Symbol]
A bare (nil receiver) call names a
let; a dynamic-dispatch call such assend(:foo)names its literal first argument.
Class Method Details
.references_in(node) ⇒ Object
A bare (nil receiver) call names a let; a dynamic-dispatch call
such as send(:foo) names its literal first argument.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/rspec/unused_let/references.rb', line 29 def references_in(node) #: Array[Symbol] return [] unless node.send_type? send = node #: untyped names = [] #: Array[Symbol] if send.receiver.nil? names << send.method_name names << :subject if SUBJECT_ALIASES.include?(send.method_name) end if DYNAMIC_DISPATCH_METHODS.include?(send.method_name) arg = send.first_argument names << arg.value.to_sym if arg&.type?(:sym, :str) end names end |
Instance Method Details
#self?.references_in ⇒ Array[Symbol]
A bare (nil receiver) call names a let; a dynamic-dispatch call
such as send(:foo) names its literal first argument.
25 |
# File 'sig/rubocop/cop/rspec/unused_let/references.rbs', line 25
def self?.references_in: (RuboCop::AST::Node node) -> Array[Symbol]
|