Class: RuboCop::Cop::RSpec::UnusedLet::Scope
- Inherits:
-
Object
- Object
- RuboCop::Cop::RSpec::UnusedLet::Scope
- Defined in:
- lib/rubocop/cop/rspec/unused_let/scope.rb,
sig/rubocop/cop/rspec/unused_let/scope.rbs
Overview
A mutable record of one example or shared group: the definitions it makes, the references it makes (kept apart by whether they sit in a helper body or in an example), whether an example runs in it, whether it pulls in a shared example group, and which of its definitions have been resolved to a reference.
Defined Under Namespace
Classes: Definition
Instance Attribute Summary collapse
- #carries_examples ⇒ Boolean readonly
- #defs ⇒ Array[Definition] readonly
- #inclusion ⇒ Boolean
- #kind ⇒ kind readonly
- #node ⇒ RuboCop::AST::Node readonly
- #refs ⇒ Set[Symbol] readonly
- #refs_in_example ⇒ Set[Symbol] readonly
- #resolved ⇒ Set[Symbol] readonly
- #tags ⇒ Array[Symbol] readonly
- #type ⇒ Symbol? readonly
Instance Method Summary collapse
- #add_definition(helper, name, def_node, alias_name: nil) ⇒ void
- #add_reference(name) ⇒ void
- #add_reference_in_example(name) ⇒ void
-
#carries_examples? ⇒ Boolean
Whether an example runs in this group or in an example group nested in it.
- #defined_names ⇒ Array[Symbol]
-
#initialize(node:, kind:, type: nil, tags: [], carries_examples: false) ⇒ Scope
constructor
A new instance of Scope.
- #mark_inclusion ⇒ void
- #mark_referenced(name) ⇒ void
- #shared? ⇒ Boolean
- #unreferenced_defs ⇒ Array[Definition]
Constructor Details
#initialize(node:, kind:, type: nil, tags: [], carries_examples: false) ⇒ Scope
Returns a new instance of Scope.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 63 def initialize(node:, kind:, type: nil, tags: [], carries_examples: false) #: void @node = node @kind = kind @defs = [] @refs = Set.new @refs_in_example = Set.new @inclusion = false @type = type @tags = @resolved = Set.new @carries_examples = carries_examples end |
Instance Attribute Details
#carries_examples ⇒ Boolean (readonly)
123 124 125 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 123 def carries_examples @carries_examples end |
#defs ⇒ Array[Definition] (readonly)
50 51 52 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 50 def defs @defs end |
#inclusion ⇒ Boolean
53 54 55 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 53 def inclusion @inclusion end |
#kind ⇒ kind (readonly)
49 50 51 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 49 def kind @kind end |
#node ⇒ RuboCop::AST::Node (readonly)
48 49 50 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 48 def node @node end |
#refs ⇒ Set[Symbol] (readonly)
51 52 53 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 51 def refs @refs end |
#refs_in_example ⇒ Set[Symbol] (readonly)
52 53 54 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 52 def refs_in_example @refs_in_example end |
#resolved ⇒ Set[Symbol] (readonly)
56 57 58 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 56 def resolved @resolved end |
#tags ⇒ Array[Symbol] (readonly)
55 56 57 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 55 def @tags end |
#type ⇒ Symbol? (readonly)
54 55 56 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 54 def type @type end |
Instance Method Details
#add_definition(helper, name, def_node, alias_name: nil) ⇒ void
This method returns an undefined value.
80 81 82 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 80 def add_definition(helper, name, def_node, alias_name: nil) #: void defs << Definition.new(helper, name, [name, alias_name].compact.uniq, def_node) end |
#add_reference(name) ⇒ void
This method returns an undefined value.
85 86 87 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 85 def add_reference(name) #: void refs << name end |
#add_reference_in_example(name) ⇒ void
This method returns an undefined value.
90 91 92 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 90 def add_reference_in_example(name) #: void refs_in_example << name end |
#carries_examples? ⇒ Boolean
Whether an example runs in this group or in an example group nested in it.
109 110 111 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 109 def carries_examples? #: bool carries_examples end |
#defined_names ⇒ Array[Symbol]
113 114 115 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 113 def defined_names #: Array[Symbol] defs.flat_map(&:names).uniq end |
#mark_inclusion ⇒ void
This method returns an undefined value.
94 95 96 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 94 def mark_inclusion #: void self.inclusion = true end |
#mark_referenced(name) ⇒ void
This method returns an undefined value.
99 100 101 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 99 def mark_referenced(name) #: void resolved << name end |
#shared? ⇒ Boolean
103 104 105 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 103 def shared? #: bool kind == :shared end |
#unreferenced_defs ⇒ Array[Definition]
117 118 119 |
# File 'lib/rubocop/cop/rspec/unused_let/scope.rb', line 117 def unreferenced_defs #: Array[Definition] defs.reject { |definition| definition.names.any? { resolved.include?(_1) } } end |