Sdlc/Dry/DuplicatedStatementSequence: carve out local-assignment and cross-class windows by shape #1345

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

Problem

Sdlc/Dry/DuplicatedStatementSequence flags 2 consecutive statements of a def body that equal a 2-statement window of an earlier def in the same file. Some of these windows cannot be extracted into a shared method.
Counterexamples:

  1. Local-variable setup that the caller reads later. Extraction cannot return it: issues = []; fixes = [] (plugins/cc-architect/scripts/plugin_config/operations/audit.rb:35-36 and :83-84).
  2. Windows in two different classes. No method is callable from both (official-cc-docs/bin/offense-log.rb:88-89 in ExplanationWriter, :125-126 in ExplanationLookup).
  3. Test duplication is carved out by a config Exclude of test paths (.rubocop.yml:234-244). That breaks the no-exclusion rule, and it leaks: plugins/os-me/hooks/test/invocation_log_test.rb:40-41 still fires.

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

Approach

Carve out by shape in the cop matcher, never by config Exclude or test-path exclusion. Skip windows whose statements are only local assignments. Skip windows that sit in a different class or module than the earlier match. Delete the test-path Exclude from .rubocop.yml and decide test duplication by shape.

Required work:

  1. Remove the test-path Exclude for the cop — check: absent DuplicatedStatementSequence in .rubocop.yml

Acceptance criteria

  1. Given each counterexample under Problem, when the cop runs, then it reports no offense.
  2. Given the true-positive shape the cop targets, when the cop runs, then it still reports an offense.
  3. Given the repo, when rubocop runs, then no Exclude list or test-path exclusion carries the carve-out.

Owner sketch

The carve-out lives in the cop matcher.

Origin

  • Trigger: the #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: false positive on valid code <- cop matcher too broad <- DESIGN (cop source: plugins/os-sdlc/lib/os_sdlc/cops/duplicated_statement_sequence.rb)
  • Root candidate: none found; searched DuplicatedStatementSequence, statement sequence, false positive, carve, local assignment
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/duplicated_statement_sequence.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 `Sdlc/Dry/DuplicatedStatementSequence` flags 2 consecutive statements of a def body that equal a 2-statement window of an earlier def in the same file. Some of these windows cannot be extracted into a shared method. Counterexamples: 1. Local-variable setup that the caller reads later. Extraction cannot return it: `issues = []; fixes = []` (plugins/cc-architect/scripts/plugin_config/operations/audit.rb:35-36 and :83-84). 2. Windows in two different classes. No method is callable from both (official-cc-docs/bin/offense-log.rb:88-89 in ExplanationWriter, :125-126 in ExplanationLookup). 3. Test duplication is carved out by a config `Exclude` of test paths (.rubocop.yml:234-244). That breaks the no-exclusion rule, and it leaks: plugins/os-me/hooks/test/invocation_log_test.rb:40-41 still fires. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md). ## Approach Carve out by shape in the cop matcher, never by config `Exclude` or test-path exclusion. Skip windows whose statements are only local assignments. Skip windows that sit in a different class or module than the earlier match. Delete the test-path `Exclude` from .rubocop.yml and decide test duplication by shape. Required work: 1. Remove the test-path Exclude for the cop — check: absent `DuplicatedStatementSequence` in `.rubocop.yml` ## Acceptance criteria 1. Given each counterexample under Problem, when the cop runs, then it reports no offense. 2. Given the true-positive shape the cop targets, when the cop runs, then it still reports an offense. 3. Given the repo, when rubocop runs, then no `Exclude` list or test-path exclusion carries the carve-out. ## Owner sketch The carve-out lives in the cop matcher. ## Origin - Trigger: the #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: false positive on valid code <- cop matcher too broad <- DESIGN (cop source: plugins/os-sdlc/lib/os_sdlc/cops/duplicated_statement_sequence.rb) - Root candidate: none found; searched DuplicatedStatementSequence, statement sequence, false positive, carve, local assignment - Where: plugins/os-sdlc/lib/os_sdlc/cops/duplicated_statement_sequence.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#1345
No description provided.