Module: Shirobai::RSpec

Defined in:
lib/shirobai-rspec.rb,
lib/shirobai/rspec/version.rb,
lib/shirobai/rspec/node_locator.rb

Overview

Glue for the shirobai-rspec plugin gem: the packed-config segment (RSpec/Language role lists + per-cop settings) and the per-file gate.

Defined Under Namespace

Modules: NodeLocator

Constant Summary collapse

COP_CLASSES =

Wrapper cop classes, appended as cops land. The per-file gate below is the union of their relevant_file? — by construction it can never be narrower than what any wrapper will ask for.

[
  Shirobai::Cop::RSpec::VariableName,
  Shirobai::Cop::RSpec::LetSetup,
  Shirobai::Cop::RSpec::VariableDefinition,
  Shirobai::Cop::RSpec::MultipleMemoizedHelpers,
  Shirobai::Cop::RSpec::RepeatedDescription,
  Shirobai::Cop::RSpec::RepeatedExample,
  Shirobai::Cop::RSpec::NamedSubject,
  Shirobai::Cop::RSpec::Focus,
  Shirobai::Cop::RSpec::PendingWithoutReason,
  Shirobai::Cop::RSpec::DescribedClass,
  Shirobai::Cop::RSpec::MetadataStyle,
  Shirobai::Cop::RSpec::DuplicatedMetadata,
  Shirobai::Cop::RSpec::EmptyMetadata,
  Shirobai::Cop::RSpec::SortMetadata,
  Shirobai::Cop::RSpec::EmptyExampleGroup,
  Shirobai::Cop::RSpec::EmptyLineAfterExample,
  Shirobai::Cop::RSpec::EmptyLineAfterExampleGroup,
  Shirobai::Cop::RSpec::EmptyLineAfterFinalLet,
  Shirobai::Cop::RSpec::EmptyLineAfterHook,
  Shirobai::Cop::RSpec::EmptyLineAfterSubject,
  Shirobai::Cop::RSpec::ScatteredSetup
].freeze
ROLE_PATHS =

config['RSpec']['Language'] sub-role paths in the fixed wire order of the rspec segment's lists (see BundleConfig in crates/shirobai-core/src/rules/bundle.rs and crates/shirobai-core/src/rules/rspec_language.rs).

[
  %w[ExampleGroups Regular], %w[ExampleGroups Focused],
  %w[ExampleGroups Skipped],
  %w[Examples Regular], %w[Examples Focused], %w[Examples Skipped],
  %w[Examples Pending],
  %w[Expectations], %w[Helpers], %w[Hooks], %w[ErrorMatchers],
  %w[Includes Examples], %w[Includes Context],
  %w[SharedGroups Examples], %w[SharedGroups Context],
  %w[Subjects]
].freeze
VERSION =

Locked to the shirobai core gem version (release train: both gems ship together and the gemspec pins shirobai to this exact version).

"2026.0709.0000"

Class Method Summary collapse

Class Method Details

.relevant_file?(config, path) ⇒ Boolean

Per-file gate for Shirobai::Dispatch: does any wrapper cop run on this file? Wrapper cops are departmental (RSpec Include: **/*_spec.rb / **/spec/**/* + factory Excludes resolve into every cop's config), so most files of a mixed codebase keep the rspec origin dormant and never build its rules.

Returns:

  • (Boolean)


128
129
130
# File 'lib/shirobai-rspec.rb', line 128

def relevant_file?(config, path)
  gate_cops(config).any? { |cop| cop.relevant_file?(path) }
end

.segment(config) ⇒ Object

The rspec origin's [nums, lists] segment for config, memoized by config identity (also the standalone fallback path's argument source). Reads the RESOLVED RSpec/Language hash — RuboCop's config layer has already applied inherit_mode: merge — and flattens it; no merging happens here.

Contract for malformed configs: when the department or Language hash is missing (e.g. rubocop-rspec required as a library without plugins:, so its default.yml was never merged), the segment is dormant. Note that a dormant segment only covers shirobai's side: without plugins: the stock RSpec cops usually resolve to Enabled: false, but NewCops: enable turns them on without their default.yml Includes, and the non-replaced stock cops then fire on non-spec files. That is a user misconfiguration outside shirobai's control; shirobai's own segment stays dormant either way. Non-Array role values and non-String list entries are dropped — a Symbol in a role list never matches in stock either (Array#include? compares against element.to_s).



118
119
120
121
# File 'lib/shirobai-rspec.rb', line 118

def segment(config)
  @segments ||= {}.compare_by_identity
  @segments[config] ||= compute_segment(config)
end