Sdlc/Structural/ModuleOwnsInstanceState: skip singleton modules #1372

Open
opened 2026-10-25 21:23:24 +00:00 by jared · 0 comments
Owner

Problem

Sdlc/Structural/ModuleOwnsInstanceState fires on singleton modules.
Shape: a module whose direct instance defs contain initialize or any ivar read or write.
With extend self or module_function, the ivar lives on the module object, not on includers.
There is no disguised inheritance and no class to convert to.

Observed

7 hits (6 test helpers, plugins/os-adr/lib/adr/root_flag.rb:4).
Sample code that fires:

module Settings
  extend self

  def values
    @values ||= { mode: "fast" }
  end
end

module Registry
  module_function

  def entries
    @entries ||= []
  end
end

Reproduce

Run the cop on the sample above.

Approach

Required work:

  1. Skip a module whose body has extend self or module_function.

Carve-outs go in the cop matcher. Do not add config Exclude lists or test-path exclusions.

Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md)

Origin

  • Trigger: #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: false positive on valid code ← cop matcher tests a proxy shape, not the real condition ← DESIGN (cop source named in Where:)
  • Root candidate: none found; searched the cop name, its mechanism terms, and false positive
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/module_owns_instance_state.rb:14-26 (module_owns_instance_state/direct_defs.rb:13-18)
  • Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl

VERDICT: CREATE

## Problem Sdlc/Structural/ModuleOwnsInstanceState fires on singleton modules. Shape: a module whose direct instance defs contain `initialize` or any ivar read or write. With `extend self` or `module_function`, the ivar lives on the module object, not on includers. There is no disguised inheritance and no class to convert to. ## Observed 7 hits (6 test helpers, plugins/os-adr/lib/adr/root_flag.rb:4). Sample code that fires: ```ruby module Settings extend self def values @values ||= { mode: "fast" } end end module Registry module_function def entries @entries ||= [] end end ``` ## Reproduce Run the cop on the sample above. ## Approach Required work: 1. Skip a module whose body has `extend self` or `module_function`. Carve-outs go in the cop matcher. Do not add config Exclude lists or test-path exclusions. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md) ## Origin - Trigger: #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: false positive on valid code ← cop matcher tests a proxy shape, not the real condition ← DESIGN (cop source named in Where:) - Root candidate: none found; searched the cop name, its mechanism terms, and false positive - Where: plugins/os-sdlc/lib/os_sdlc/cops/module_owns_instance_state.rb:14-26 (module_owns_instance_state/direct_defs.rb:13-18) - Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl VERDICT: CREATE
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#1372
No description provided.