Class: Shirobai::Cop::RSpec::LetSetup

Inherits:
RuboCop::Cop::Base
  • Object
show all
Includes:
BundleEligible
Defined in:
lib/shirobai/cop/rspec/let_setup.rb

Overview

Drop-in Rust reimplementation of RSpec/LetSetup (rubocop-rspec 3.10.2).

Everything is computed on the shared walk: query roots are scope-change frames (example/shared groups with an rspec receiver and include_* blocks), candidates are collected lets literally named let! with one plain sym/str name, an inner let! shadowed check compares (kind, value) — let!('w') and let!(:w) do not shadow each other — and "used" means a receiverless ZERO-argument send with the same name anywhere in the root's subtree (stock's (send nil? %) search pattern has no argument wildcard, so w(1) and w(&b) are not uses while w { } is). Probed quirks live as differential specs in let_setup_edge_cases_spec.rb.

Constant Summary collapse

MSG =
"Do not use `let!` to setup objects not referenced in tests."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



25
# File 'lib/shirobai/cop/rspec/let_setup.rb', line 25

def self.badge = RuboCop::Cop::Badge.parse(cop_name)

.bundle_args(_config) ⇒ Object

Config-less (the segment's role lists cover everything).



28
29
30
# File 'lib/shirobai/cop/rspec/let_setup.rb', line 28

def self.bundle_args(_config)
  []
end

.cop_nameObject



24
# File 'lib/shirobai/cop/rspec/let_setup.rb', line 24

def self.cop_name = "RSpec/LetSetup"

Instance Method Details

#on_new_investigationObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shirobai/cop/rspec/let_setup.rb', line 32

def on_new_investigation
  offenses = resolved_offenses
  return if offenses.empty?

  buffer = processed_source.buffer
  source = bundle_eligible? ? processed_source.raw_source : buffer.source
  off = SourceOffsets.for(source)
  offenses.each do |(start, fin)|
    add_offense(Parser::Source::Range.new(buffer, off[start], off[fin]))
  end
end