Extract a shared ClassSiteCop base for the two ClassSite-driven cops #659

Closed
opened 2026-09-24 01:15:10 +00:00 by jared · 2 comments
Owner

Problem

lib/os_sdlc/cops/instance_variable_assumption.rb:18 and lib/os_sdlc/cops/primitive_obsessed_ivar.rb:18 contain byte-identical code defining on_class and Offense struct. Each cop defines its own nested ClassSite class; the only difference is which ClassSite constant resolves. flay reports IDENTICAL, mass*2 = 64.

Reproduce

n/a: refactor ticket, no runtime defect

Approach

Add lib/os_sdlc/cops/class_site_cop.rb, a base class inheriting from the same RuboCop base the two cops use today. It holds the Offense struct and on_class, resolving self.class::ClassSite. Both cops inherit from it and keep only their ClassSite.

Required work:

  1. add ClassSiteCop base
  2. make both cops inherit from it and delete the duplicated on_class and Offense
  3. existing cop tests stay green
  4. flay on lib no longer reports this pair

Acceptance criteria

  1. flay plugins/os-sdlc/lib no longer lists the pair
  2. tests/cops/*_test.rb green
  3. rubocop clean on touched files

Owner sketch

OsSdlc::Cops::ClassSiteCop in lib/os_sdlc/cops/class_site_cop.rb owns the offense loop and the Offense struct.

class ClassSiteCop < RuboCop::Cop::Base
  Offense = Struct.new(:node, :message)

  def on_class(node)
    self.class::ClassSite.new(node).offenses.each do |offense|
      add_offense(offense.node, message: offense.message)
    end
  end
end

InstanceVariableAssumption and PrimitiveObsessedIvar inherit from it and keep only their nested ClassSite.

Origin

Session: 24f1de09-c081-4958-902b-0512a5d86e04
Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/24f1de09-c081-4958-902b-0512a5d86e04.jsonl
Where: lib/os_sdlc/cops/
Source: flay duplication sweep (bin/dup-sweep) run 2026-09-23 on plugins/os-sdlc; lib+bin score 726.

## Problem lib/os_sdlc/cops/instance_variable_assumption.rb:18 and lib/os_sdlc/cops/primitive_obsessed_ivar.rb:18 contain byte-identical code defining on_class and Offense struct. Each cop defines its own nested ClassSite class; the only difference is which ClassSite constant resolves. flay reports IDENTICAL, mass*2 = 64. ## Reproduce n/a: refactor ticket, no runtime defect ## Approach Add lib/os_sdlc/cops/class_site_cop.rb, a base class inheriting from the same RuboCop base the two cops use today. It holds the Offense struct and on_class, resolving `self.class::ClassSite`. Both cops inherit from it and keep only their ClassSite. Required work: 1. add ClassSiteCop base 2. make both cops inherit from it and delete the duplicated on_class and Offense 3. existing cop tests stay green 4. flay on lib no longer reports this pair ## Acceptance criteria 1. flay plugins/os-sdlc/lib no longer lists the pair 2. tests/cops/*_test.rb green 3. rubocop clean on touched files ## Owner sketch `OsSdlc::Cops::ClassSiteCop` in `lib/os_sdlc/cops/class_site_cop.rb` owns the offense loop and the `Offense` struct. ```ruby class ClassSiteCop < RuboCop::Cop::Base Offense = Struct.new(:node, :message) def on_class(node) self.class::ClassSite.new(node).offenses.each do |offense| add_offense(offense.node, message: offense.message) end end end ``` `InstanceVariableAssumption` and `PrimitiveObsessedIvar` inherit from it and keep only their nested `ClassSite`. ## Origin Session: 24f1de09-c081-4958-902b-0512a5d86e04 Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/24f1de09-c081-4958-902b-0512a5d86e04.jsonl Where: lib/os_sdlc/cops/ Source: flay duplication sweep (bin/dup-sweep) run 2026-09-23 on plugins/os-sdlc; lib+bin score 726.
Author
Owner

Work started via /os-sdlc:implement on branch ticket-659 (session 24f1de09).

Work started via /os-sdlc:implement on branch ticket-659 (session 24f1de09).
Author
Owner

Resolution

Done: ClassSiteCop base extracted in RuboCop::Cop::Sdlc::Structural; both cops and their nested reopenings inherit it; duplicated on_class and Offense removed.

Evidence: Pipeline impl 3 on coding.yaml: programmer gate test+lint green, reviewer pass. flay lib+bin 726 -> 662; the pair no longer listed. Branch ticket-659.

Follow-ups: none

## Resolution **Done:** ClassSiteCop base extracted in RuboCop::Cop::Sdlc::Structural; both cops and their nested reopenings inherit it; duplicated on_class and Offense removed. **Evidence:** Pipeline impl 3 on coding.yaml: programmer gate test+lint green, reviewer pass. flay lib+bin 726 -> 662; the pair no longer listed. Branch ticket-659. **Follow-ups:** none
jared closed this issue 2026-09-24 01:38:15 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#659
No description provided.