Sdlc/Structural/FormatValidationRaisingInInitialize: stop flagging the value object the fix creates #1355

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

Problem

The cop Sdlc/Structural/FormatValidationRaisingInInitialize flags the value object that its own fix creates.
The fix says: extract a value object that validates in its own initialize (format_validation_raising_in_initialize.rb:57-61).
The cop then flags that value object when it uses the modifier form of the guard.

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

Observed

The cop flags this prescribed target:

class TicketNumber
  FORMAT = /\A[a-z0-9-]+\z/

  def initialize(value)
    @value = value.to_s
    raise ArgumentError, "bad ticket number" unless @value.match?(FORMAT)
  end
end

The cop test passes only the guard-clause form (tests/cops/format_validation_raising_in_initialize_test.rb:42-45).
The cop has 0 hits in plugins/.

Reproduce

n/a: matcher is plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb:18-50; run the cop on the sample above.

Approach

Carve-outs go in the cop matcher, never in a config Exclude list or a test-path exclusion.
Skip an initialize whose class's only state is the validated param (one ivar assigned from the one param), in both the modifier and the guard-clause form.

Required work:

  1. Add the single-value-class carve-out — check: present ivar in plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb

Acceptance criteria

  1. Given a class whose initialize assigns one ivar from its one param and raises unless @value.match?(FORMAT), when the cop runs, then it reports no offense.
  2. Given a class with other state that validates a format in initialize, when the cop runs, then it still reports an offense.

Origin

  • Trigger: #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: cop flags its own fix target ← matcher has no single-value-class check ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb)
  • Root candidate: none found; searched FormatValidationRaisingInInitialize
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb
  • 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 The cop `Sdlc/Structural/FormatValidationRaisingInInitialize` flags the value object that its own fix creates. The fix says: extract a value object that validates in its own initialize (`format_validation_raising_in_initialize.rb:57-61`). The cop then flags that value object when it uses the modifier form of the guard. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md). ## Observed The cop flags this prescribed target: ```ruby class TicketNumber FORMAT = /\A[a-z0-9-]+\z/ def initialize(value) @value = value.to_s raise ArgumentError, "bad ticket number" unless @value.match?(FORMAT) end end ``` The cop test passes only the guard-clause form (`tests/cops/format_validation_raising_in_initialize_test.rb:42-45`). The cop has 0 hits in plugins/. ## Reproduce n/a: matcher is `plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb:18-50`; run the cop on the sample above. ## Approach Carve-outs go in the cop matcher, never in a config Exclude list or a test-path exclusion. Skip an `initialize` whose class's only state is the validated param (one ivar assigned from the one param), in both the modifier and the guard-clause form. Required work: 1. Add the single-value-class carve-out — check: present `ivar` in `plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb` ## Acceptance criteria 1. Given a class whose `initialize` assigns one ivar from its one param and raises `unless @value.match?(FORMAT)`, when the cop runs, then it reports no offense. 2. Given a class with other state that validates a format in `initialize`, when the cop runs, then it still reports an offense. ## Origin - Trigger: #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: cop flags its own fix target ← matcher has no single-value-class check ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb) - Root candidate: none found; searched FormatValidationRaisingInInitialize - Where: plugins/os-sdlc/lib/os_sdlc/cops/format_validation_raising_in_initialize.rb - 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#1355
No description provided.